Codeforce 515 B . Drazil and His Happy Friends
来源:互联网 发布:网络管理队伍状况 编辑:程序博客网 时间:2024/06/07 01:08
传送门:http://codeforces.com/contest/515/problem/B
题目大意:
给出一个n,m,代表男女的数量,第i天让i%n号男和i%m号女约会,如果他们其中有一个人是 开心的,那么另一个人也会变开心,问能否通过有限次约会让他们都开心。
题目分析:
直接模拟100000次,然后判断是否依旧存在不开心的人即可,因为存在循环节,懒得算循环节长度,所以直接100000了。。。反正不会超时。
#include<iostream>#include <cstdio>#include <string.h>#include <algorithm>#include <math.h>using namespace std;int a[110], b[110];int main(){#ifndef ONLINE_JUDGE freopen("1.txt", "r", stdin);#endif int n, m, i, j, x, y, boy, girl; bool flag; while(~scanf("%d%d", &n, &m)) { flag = false; memset(a, 0, sizeof(a)); memset(b, 0, sizeof(b)); cin >> x; boy = x; for (i = 0; i < x; i++) { cin >> y; a[y] = 1; } cin >> x; girl = x; for (i = 0; i < x; i++) { cin >> y; b[y] = 1; } for (i = 0; i < 100000 ; i++) { if (a[i%n] == 0 && b[i%m] == 0) { continue; } else if (a[i%n] == 1 && b[i%m] == 0) { b[i%m] = 1; girl++; } else if (a[i%n] == 0 && b[i%m] == 1) { a[i%n] = 1; boy++; } if (boy == n && girl == m) { flag = true; break; } } if (flag) { cout << "Yes\n"; } else { cout << "No\n"; } } return 0;}
0 0
- Codeforce 515 B . Drazil and His Happy Friends 暴力
- Codeforce 515 B . Drazil and His Happy Friends
- 515B. Drazil and His Happy Friends
- codeforces 515B B. Drazil and His Happy Friends(模拟)
- B. Drazil and His Happy Friends
- B. Drazil and His Happy Friends
- B. Drazil and His Happy Friends
- CodeForces - 515B Drazil and His Happy Friends
- CodeForces515B Drazil and His Happy Friends (数学)
- Codeforces Round #292 (Div. 2) -- B. Drazil and His Happy Friends
- [数论] Codeforces 516E. Drazil and His Happy Friends
- [数论] Codeforces 819D R #421 D.Mister B and Astronomers & 516E R #292 E. Drazil and His Happy Friends
- Codeforce 515 C . Drazil and Factorial 规律
- codeforces#292B_Drazil and His Happy Friends-暴力水题
- codeforce 793 B Igor and his way to work
- Igor and his way to work-Codeforce 793B BFS
- CodeForce l-Friends and Presents
- Codeforce 894B Ralph And His Magic Field (思维+快速幂)
- ASP.NET常见对象之Cookie、Session与Application
- Error initializing Java Runtime Environment. You may need to reinstall Flash
- hdu 5418 Victor and World 状态压缩dp spfa最短路 floyed最短路
- 图论 - zoj3811 Untrusted Patrol
- HDOJ 5409 CRB and Graph 无向图缩块
- Codeforce 515 B . Drazil and His Happy Friends
- android与服务器之间数据通信(struts2+JSON+android)
- Tomcat8源码编译及导入Eclipse中研究
- C# 之 FTP服务器中文件上传与下载(一)
- NBUT 1455 Malphite
- hdu5417(BC)
- 欢迎使用CSDN-markdown编辑器
- android L 启动流程
- securet crt不能配置了