CodeForces 515B. Drazil and His Happy Friends
2 seconds
256 megabytes
standard input
standard output
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan.
There are n boys and m girls among his friends. Let's number them from 0 to n - 1 and 0 to m - 1 separately. In i-th day, Drazil invites -th boy and -th girl to have dinner together (as Drazil is programmer, i starts from 0). If one of those two people is happy, the other one will also become happy. Otherwise, those two people remain in their states. Once a person becomes happy (or if he/she was happy originally), he stays happy forever.
Drazil wants to know whether he can use this plan to make all his friends become happy at some moment.
The first line contains two integer n and m (1 ≤ n, m ≤ 100).
The second line contains integer b (0 ≤ b ≤ n), denoting the number of happy boys among friends of Drazil, and then follow b distinct integers x1, x2, ..., xb (0 ≤ xi < n), denoting the list of indices of happy boys.
The third line conatins integer g (0 ≤ g ≤ m), denoting the number of happy girls among friends of Drazil, and then follow g distinct integers y1, y2, ... , yg (0 ≤ yj < m), denoting the list of indices of happy girls.
It is guaranteed that there is at least one person that is unhappy among his friends.
If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No".
2 3
0
1 0
Yes
2 4
1 0
1 2
No
2 3
1 0
1 1
Yes
By we define the remainder of integer division of i by k.
In first sample case:
- On the 0-th day, Drazil invites 0-th boy and 0-th girl. Because 0-th girl is happy at the beginning, 0-th boy become happy at this day.
- On the 1-st day, Drazil invites 1-st boy and 1-st girl. They are both unhappy, so nothing changes at this day.
- On the 2-nd day, Drazil invites 0-th boy and 2-nd girl. Because 0-th boy is already happy he makes 2-nd girl become happy at this day.
- On the 3-rd day, Drazil invites 1-st boy and 0-th girl. 0-th girl is happy, so she makes 1-st boy happy.
- On the 4-th day, Drazil invites 0-th boy and 1-st girl. 0-th boy is happy, so he makes the 1-st girl happy. So, all friends become happy at this moment.
题目意思很简单,就是看,能否在最后使所有的人都快乐。
第一发错了,在用i的值进行遍历的时候,第二次直接让i <= 1000000,过了,所以 i 到底该取多大,我是不知道的。再想想
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <ctype.h>
#define mem(a, b) memset((a), (b), (sizeof(a)))
using namespace std;
const int max_size = ; int main()
{
int n, m;
int boy[max_size];
int girl[max_size];
mem(boy, );
mem(girl, );
int boy_num, b;
int girl_num, g;
cin >> n >> m;
cin >> boy_num;
for(int i = ; i < boy_num; i++)
{
cin >> b;
boy[b] = ;
}
cin >> girl_num;
for(int i = ; i < girl_num; i++)
{
cin >> g;
girl[g] = ;
} for(int i = ; i <= ; i++)
{
b = i % n;
g = i % m;
if(boy[b]+girl[g])
{
boy[b] = ;
girl[g] = ;
}
}
bool tag = true;
for(int i = ; i < n; i++)
{
if(boy[i] == )
tag = false; }
for(int i = ; i < m; i++)
{
if(girl[i] == )
tag = false;
}
if(tag == false)
cout << "No" << endl;
else
cout << "Yes" << endl;
return ;
}
CodeForces 515B. Drazil and His Happy Friends的更多相关文章
- codeforces 515B. Drazil and His Happy Friends 解题报告
题目链接:http://codeforces.com/problemset/problem/515/B 题目意思:有 n 个 boy 和 m 个 girl,有 b 个 boy 和 g 个 girl ( ...
- 【codeforces 515B】Drazil and His Happy Friends
[题目链接]:http://codeforces.com/contest/515/problem/B [题意] 第i天选择第i%n个男生,第i%m个女生,让他们一起去吃饭; 只要这一对中有一个人是开心 ...
- CodeForces - 516B Drazil and Tiles(bfs)
https://vjudge.net/problem/CodeForces-516B 题意 在一个n*m图中放1*2或者2*1的长方形,问是否存在唯一的方法填满图中的‘.’ 分析 如果要有唯一的方案, ...
- CodeForces 515C. Drazil and Factorial
C. Drazil and Factorial time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- codeforces 515C. Drazil and Factorial 解题报告
题目链接:http://codeforces.com/problemset/problem/515/C 题目意思:给出含有 n 个只有阿拉伯数字的字符串a(可能会有前导0),设定函数F(a) = 每个 ...
- codeforces 515A.Drazil and Date 解题报告
题目链接:http://codeforces.com/problemset/problem/515/A 题目意思:问能否从 (0, 0) 出发,恰好走 s 步,到达该位置(a, b). 首先容易知道, ...
- CodeForces 516C Drazil and Park 线段树
原文链接http://www.cnblogs.com/zhouzhendong/p/8990745.html 题目传送门 - CodeForces 516C 题意 在一个环上,有$n$棵树. 给出每一 ...
- CodeForces 516B Drazil and Tiles 其他
原文链接http://www.cnblogs.com/zhouzhendong/p/8990658.html 题目传送门 - CodeForces 516B 题意 给出一个$n\times m$的矩形 ...
- CodeForces 516A Drazil and Factorial 动态规划
原文链接http://www.cnblogs.com/zhouzhendong/p/8990592.html 题目传送门 - CodeForces 516A 题意 对于一个正整数$x$,$f(x)=x ...
随机推荐
- python 模块基础介绍
从逻辑上组织代码,将一些有联系,完成特定功能相关的代码组织在一起,这些自我包含并且有组织的代码片段就是模块,将其他模块中属性附加到你的模块的操作叫做导入. 那些一个或多个.py文件组成的代码集合就称为 ...
- C# *= 运算顺序
a *= a + b *c; 不管等号右边有没有括号,总是先算右边: 即等价于 a = a *(a + b*c); using System; using System.Collections.Gen ...
- 如何删除PHP数组中的元素,并且索引重排(unset,array_splice)?
如果要在某个数组中删除一个元素,可以直接用的unset,但是数组的索引不会重排: <?php $arr = array('a','b','c','d'); unset($arr[1]); pri ...
- PHP函数call_user_func和call_user_func_array详解
今天在群里面,有个叫lewis的在问call_user_func_array的用法,因为之前一直没有用过,也不能说什么,于是看一下手册,发现是这么写的: call_user_func_array (P ...
- MySQL中find_in_set()和in的区别
弄个测试表来说明两者的区别 CREATE TABLE `test` ( `id` int(8) NOT NULL auto_increment, `name` varchar(255) NOT NUL ...
- Linux下安装和配置JDK与Tomcat(升级版)
在这个版本 Linux下安装和配置JDK与Tomcat(入门版) 的基础上优化升级 1.下载相关软件 apache-tomcat-6.0.37.tar.gz jdk-6u25-linux-i586-r ...
- Nginx 限速模块一览
为了保护服务器不被刷流量,或者业务方面的一些限制,需要做一些限速措施. 一.http 请求并发连接数模块:ngx_http_limit_conn_module 这个模块可以设置每个定义的变量(比如客户 ...
- JVM相关参数的采集
1.以-jar方式启动jar包: java -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=40100 ...
- resize
resize 属性规定是否可由用户调整元素尺寸. resize: none|both|horizontal|vertical; none:用户无法调整元素的尺寸. 比较常用 both:用户可 ...
- 网站建设中帝国cms如何循环调用栏目下级分类
类似的形式,调用下级分类 ?php $bclassid=[!--self.classid--]; //选择当前栏目的id,如果调用指定栏目下的多级分类,则填写栏目id //取得本栏目下的子栏目 ? [ ...