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(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个 ...
随机推荐
- Git Book 中文版 - Git的撤消操作 - 重置, 签出 和 撤消
Git Book 中文版 - Git的撤消操作 - 重置, 签出 和 撤消 Git的撤消操作 - 重置, 签出 和 撤消 Git提供了多种修复你开发过程中的错误的方法. 方法的选择取决于你的情况: 包 ...
- Ubuntu 下安装 Oracle Java
这只是一篇流水帐,记录如何安装Java. 在Ubuntu 下管理软件很方便,但安装的Java是opensdk.如果在某些条件下,需要安装Sun (Oracle)的Java,则需要自己手工安装. 一般情 ...
- iOS WebServiceFramework网络服务框架浅解
网络服务几乎是每一款成功APP的必备条件,打开你手机你会发现里面不用联网的应用数量十只手指可以数出来,就算是一些以独特技术切入市场的APP如美颜相机,都至少加入了分享功能.下面我先做下简单的回顾兼扫盲 ...
- Base64.java 工具类
import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOExceptio ...
- C#中的where从句
C#中的where从句 2011-07-03 13:07OrphousV | 分类:C#/.NET | 浏览8443次 能解释一下下面两段代码中where的作用吗?using System;publi ...
- 云计算平台(检索篇)-Elasticsearch
前段时间为公司基于Elasticsearch(下面简称ES)做了一套检索平台,下面将这段时间积累的一些知识与大家分享,如有不对之处,欢迎大家多多批评与建议.针对Elasticsearch由于东西还是比 ...
- OA项目之左导航
左边导航(一层级,二层级,三层级,四层级) aspx: <%@ Page Language="C#" AutoEventWireup="true" Cod ...
- 具体解释Android中AsyncTask的使用
在Android中实现异步任务机制有两种方式,Handler和AsyncTask. Handler模式须要为每个任务创建一个新的线程,任务完毕后通过Handler实例向UI线程发送消息,完毕界面的更新 ...
- 错误解决:release' is unavailable: not available in automatic reference counting mode
解决办法: You need to turn off Automatic Reference Counting. You do this by clicking on your project in ...
- 类的this指针 总结
类的this指针有以下特点: (1)this只能在成员函数中使用 全局函数,静态函数都不能使用this. 实际上,成员函数默认第一个参数为T* const this. 如: class A { pub ...