Drazil and His Happy Friends
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

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.

Input

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.

Output

If Drazil can make all his friends become happy by this plan, print "Yes". Otherwise, print "No".

Sample test(s)
input
2 3
0
1 0
output
Yes
input
2 4
1 0
1 2
output
No
input
2 3
1 0
1 1
output
Yes
 
推了半天没推出规律,索性10W的暴力来一发,后来。。过了。。。。
#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的更多相关文章

  1. CF Drazil and Factorial (打表)

    Drazil and Factorial time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  2. CF Drazil and Date (奇偶剪枝)

    Drazil and Date time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  3. CF R631 div2 1330 E Drazil Likes Heap

    LINK:Drazil Likes Heap 那天打CF的时候 开场A读不懂题 B码了30min才过(当时我怀疑B我写的过于繁琐了. C比B简单多了 随便yy了一个构造发现是对的.D也超级简单 dp了 ...

  4. 【Cf #292 D】Drazil and Morning Exercise(树的直径,树上差分)

    有一个经典的问题存在于这个子问题里,就是求出每个点到其他点的最远距离. 这个问题和树的直径有很大的关系,因为事实上距离每个点最远的点一定是直径的两个端点.所以我们可以很容易地进行$3$遍$Dfs$就可 ...

  5. 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 ...

  6. CF数据结构练习

    1. CF 438D The Child and Sequence 大意: n元素序列, m个操作: 1,询问区间和. 2,区间对m取模. 3,单点修改 维护最大值, 取模时暴力对所有>m的数取 ...

  7. 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 ...

  8. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  9. cf Round 613

    A.Peter and Snow Blower(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个 ...

随机推荐

  1. Apache Spark GraphX的体系结构

    1. 整体架构 GraphX 的整体架构(如图 1所示)可以分为三部分. 图 1  GraphX 架构 存储和原语层: Graph 类是图计算的核心类.内部含有 VertexRDD. EdgeRDD ...

  2. 值栈与ognl

    ValueStack (值栈): 1.贯穿整个Action的生命周期(每个Action类的对象实例都拥有一个ValueStack对象).相当于一个数据的中转站.在其中保存当前Action对象和其他相关 ...

  3. 【Java】JDBC编程套路

    转载请注明原文地址:http://www.cnblogs.com/ygj0930/p/5847020.html 学习Java开发,一个必须掌握的知识点,就是数据库操作.当程序需要用到的数据达到一定程度 ...

  4. Activator.CreateInstance 方法 (Type) 的用法

    转自:http://www.cnblogs.com/lmfeng/archive/2012/01/30/2331666.html Activator.CreateInstance 方法 (Type) ...

  5. c# Internet时间服务器同步

    2009-02-02 17:48 8226人阅读 评论(2) 收藏 举报 服务器internetc#socketstringwindows 需要用到的名空间 using System.Net; usi ...

  6. InvokeHelper,让跨线程访问/修改主界面控件不再麻烦(转)

    http://bbs.csdn.net/topics/390162519 事实上,本文内容很简单且浅显,所以取消前戏,直接开始.. 源代码:在本文最后 这里是一张动画,演示在多线程(无限循环+Thre ...

  7. skyline TerraBuilder 制作MPT方法与技巧(1)

    MPT是skyline独有的三维地形数据格式,可简单理解为 影像图+高程=三维地形(三维底图),以下介绍用skyline TerraBuilder(以下简称TB)制作MPT的方法与技巧 用TB制作MP ...

  8. 委派RODC管理员

    将某个普通域用户(或组)委派为RODC管理员:

  9. java中匿名类的讲解

    匿名内部类也就是没有名字的内部类 正因为没有名字,所以匿名内部类只能使用一次,它通常用来简化代码编写 但使用匿名内部类还有个前提条件:必须继承一个父类或实现一个接口 实例1:不使用匿名内部类来实现抽象 ...

  10. python的一些总结2

    第一篇 写了下 基本的环境搭建和一个hello world 程序 下面 介绍接下 怎么使用 python 搭建一个网站.(中间的语法教学 请参考->http://www.liaoxuefeng. ...