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(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个 ...
随机推荐
- HDU 5919 -- Sequence II (主席树)
题意: 给一串数字,每个数字的位置是这个数第一次出现的位置. 每个询问对于序列的一个子区间,设一共有k个不同的数,求第ceil(k/2)个数的位置. 因为强制在线,所以离线乱搞pass掉. 主席树可解 ...
- work5
这一次写的内容是黄金豆小游戏,由于现在偏重写服务器端.对于算法层面其实涉及不多,更多偏于工程上的架构. 总而言之本次作业的服务器核心是用web.py所写,而且为了方便其他用户写客户端,架构非常简单. ...
- Java设计模式系列之适配器模式
适配器模式的定义 将一个类的接口转换成客户希望的另外一个接口.Adapter模式使得原本由于接口不兼容而不能一起工作的那些类可以一起工作.(就类似于我们充电器的转接头将220V的电压转换成我们的手机端 ...
- HDU 1142 A Walk Through the Forest (求最短路条数)
A Walk Through the Forest 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1142 Description Jimmy exp ...
- javascript实现颜色渐变
渐变(Gradient)是美学中一条重要的形式美法则,与其相对应的是突变.形状.大小.位置.方向.色彩等视觉因素都可以进行渐变.在色彩中,色相.明度.纯度也都可以产生渐变效果,并会表现出具有丰富层次的 ...
- CodeForces 732A Buy a Shovel (水题)
题意:你手中有10元的钱,还有一个r元的零钱,要买一个价格为k的物品,但是你要求不找零钱,求最少要买多少物品. 析:直接暴力,最多买10个物品就够了1-10. 代码如下: #pragma commen ...
- CreateProcess的使用方法
使用编译器vs2008. 第一.第二个參数的使用方法: 样例: 使用ie打开指定的网页. 注意第二个參数是 可运行文件+命令行參数 #include "stdafx.h" #inc ...
- Cts框架解析(12)-ITargetPreparer
測试开启前的设备系统准备工作. 接口 /* * Copyright (C) 2010 The Android Open Source Project * * Licensed under the Ap ...
- search result
https://github.com/search?l=java&p=86&q=Floating+window&type=Code&utf8=%E2%9C%93http ...
- HBuilder:最快的Web开发IDE
这里给大家介绍一个个人觉得最好用的web开发工具:Hbuilder. HBuilder是DCloud推出的一款支持HTML5的Web开发IDE.快,是HBuilder的最大优势,通过完整的语法提示和代 ...