CF 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
#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cctype>
#include <queue>
#include <map>
using namespace std; const int SIZE = ; int main(void)
{
int n,m,box;
int h_n,h_m;
int s_n[SIZE] = {};
int s_m[SIZE] = {}; cin >> n >> m; cin >> h_n;
for(int i = ;i < h_n;i ++)
{
cin >> box;
s_n[box] = ;
}
cin >> h_m;
for(int i = ;i < h_m;i ++)
{
cin >> box;
s_m[box] = ;
} for(int i = ;i < ;i ++)
if(s_n[i % n] || s_m[i % m])
s_n[i % n] = s_m[i % m] = ; int flag_1 = ;
int flag_2 = ;
for(int i = ;i < n;i ++)
if(!s_n[i])
{
flag_1 = ;
break;
}
for(int i = ;i < m;i ++)
if(!s_m[i])
{
flag_2 = ;
break;
}
if(flag_1 && flag_2)
cout << "Yes" << endl;
else
cout << "No" << endl; return ;
}
CF Drazil and His Happy Friends的更多相关文章
- CF Drazil and Factorial (打表)
Drazil and Factorial time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- CF Drazil and Date (奇偶剪枝)
Drazil and Date time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- CF R631 div2 1330 E Drazil Likes Heap
LINK:Drazil Likes Heap 那天打CF的时候 开场A读不懂题 B码了30min才过(当时我怀疑B我写的过于繁琐了. C比B简单多了 随便yy了一个构造发现是对的.D也超级简单 dp了 ...
- 【Cf #292 D】Drazil and Morning Exercise(树的直径,树上差分)
有一个经典的问题存在于这个子问题里,就是求出每个点到其他点的最远距离. 这个问题和树的直径有很大的关系,因为事实上距离每个点最远的点一定是直径的两个端点.所以我们可以很容易地进行$3$遍$Dfs$就可 ...
- Codeforces Round #292 (Div. 1) - B. Drazil and Tiles
B. Drazil and Tiles Drazil created a following problem about putting 1 × 2 tiles into an n × m gri ...
- CF数据结构练习
1. CF 438D The Child and Sequence 大意: n元素序列, m个操作: 1,询问区间和. 2,区间对m取模. 3,单点修改 维护最大值, 取模时暴力对所有>m的数取 ...
- ORA-00494: enqueue [CF] held for too long (more than 900 seconds) by 'inst 1, osid 5166'
凌晨收到同事电话,反馈应用程序访问Oracle数据库时报错,当时现场现象确认: 1. 应用程序访问不了数据库,使用SQL Developer测试发现访问不了数据库.报ORA-12570 TNS:pac ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- cf Round 613
A.Peter and Snow Blower(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个 ...
随机推荐
- libpcap/wwinpcap
winpcap(windows packet capture)是windows平台下一个免费,公共的网络访问系统.开发winpcap这个项目的目的在于为win32应用程序提供访问网络底层的能力.win ...
- iOS中的谓词(NSPredicate)使用
http://www.cocoachina.com/ios/20160111/14926.html 首先,我们需要知道何谓谓词,让我们看看官方的解释: The NSPredicate class is ...
- DB2 递归查询
上一篇中讲解了ORACLE中的递归查询,下面我们看一下DB2中如何使用递归查询: 同样的我们先新建一个表来存储以上信息,并插入测试数据: --建表 create table FAMILY ( pers ...
- HDU 5778 abs (枚举)
abs 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5778 Description Given a number x, ask positive ...
- 查杀oracle锁表
()锁表查询的代码有以下的形式: select count(*) from v$locked_object; select * from v$locked_object; ()查看哪个表被锁 sele ...
- ubuntu 如何在recovery模式修改root密码
今天遇到一个问题, 前提1: ubuntu系统的root密码我一直没有设定 前提2: ubuntu初始创建的sudo用户不知道怎么移除sudo权限用户了. 下面就精彩了, 首先没有root密码,你不 ...
- oracle连接由于防火墙设置导致超时的问题
当应用程序使用数据库连接池进行数据连接时,防火墙的设置有可能会导致连接出现超时或者被重置的问题.当从数据库读数据的时候 有可能会 Connection timed out, 这是由于应用会缓存 ...
- C语言中用宏来作注释
看了PostgreSQL的代码后,我觉得有不理解的地方,比如: 例如这样的: /* Options that may appear after CATALOG (on the same line) * ...
- 破解中国电信华为无线猫路由(HG522-C)自己主动拨号+不限电脑数+iTV
中国电信总是把好好的一个路由猫阉割过后放在我的E家套餐里到处兜售(垄断市场也就罢了,还有非常多霸王条款,比方必须使用它们的手机,同一时候最多多少台电脑上网等等),曾经破解过另外一个中国电信的路由猫,非 ...
- 小菜学习MVC4-WebApi
今天想看下MVC4的东西,发现 居然有WebApi这东西,百度了一下..居然是 WCF中的东西,然后移植到了MVC4中,WCF你懂得返回数据都是xml,向网站这种请求 就比较纠结...而webapi可 ...