【题目链接】:http://codeforces.com/contest/515/problem/B

【题意】



第i天选择第i%n个男生,第i%m个女生,让他们一起去吃饭;

只要这一对中有一个人是开心状态,另外一个人也能变成开心状态;

且开心之后就一直开心了;

给你n个男生,m个女生的状态(是否开心);

问你是否到了某一天所有人都会变的开心;

【题解】



那个i%n和i%m的循环肯定有循环节的;

找到那个循环节的长度;

每次在循环节内尝试用上述办法,看看有没有办法让某些人从不开心变为开心;

如果可以的话;就重复这个循环节地步骤;

直到没有一个人因为这个循环节的操作变成开心状态为止。



【Number Of WA】



0



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define ps push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x)
#define ref(x) scanf("%lf",&x) typedef pair<int, int> pii;
typedef pair<LL, LL> pll; const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const double pi = acos(-1.0);
const int N = 110; bool bh[N], gh[N];
int n, m,b,g;
bool bo[N][N]; int main()
{
//freopen("F:\\rush.txt", "r", stdin);
rei(n), rei(m);
rei(b);
rep1(i, 1, b)
{
int x;
rei(x);
bh[x] = true;
}
rei(g);
rep1(i, 1, g)
{
int x;
rei(x);
gh[x] = true;
}
int len = 0;
for (int i = 0;; i++)
{
int x = i%n, y = i%m;
if (bo[x][y])
{
len = i - 1;
break;
}
bo[x][y] = true;
}
bool ok = true;
while (ok)
{
ok = false;
for (int i = 0; i <= len; i++)
{
int x = i%n, y = i%m;
if (!bh[x] || !gh[y])
{
if (bh[x] || gh[y])
{
bh[x] = gh[y] = true;
ok = true;
}
}
}
}
rep1(i, 0, n - 1)
if (!bh[i])
return puts("No"), 0;
rep1(i, 0, m - 1)
if (!gh[i])
return puts("No"), 0;
puts("Yes");
//printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
return 0;
}

【codeforces 515B】Drazil and His Happy Friends的更多相关文章

  1. 【codeforces 515D】Drazil and Tiles

    [题目链接]:http://codeforces.com/contest/515/problem/D [题意] 给你一个n*m的格子; 然后让你用1*2的长方形去填格子的空缺; 如果有填满的方案且方案 ...

  2. 【codeforces 515C】Drazil and Factorial

    [题目链接]:http://codeforces.com/contest/515/problem/C [题意] 定义f(n)=n这个数各个位置上的数的阶乘的乘积; 给你a; 让你另外求一个不含0和1的 ...

  3. 【codeforces 515A】Drazil and Date

    [题目链接]:http://codeforces.com/contest/515/problem/A [题意] 每次只能走到相邻的四个格子中的一个; 告诉你最后走到了(a,b)走了多少步->s ...

  4. 【codeforces 516B】Drazil and Tiles

    题目链接: http://codeforces.com/problemset/problem/516/B 题解: 首先可以得到一个以‘.’为点的无向图,当存在一个点没有边时,无解.然后如果这个图边双联 ...

  5. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  6. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  7. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  8. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  9. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

随机推荐

  1. Knowing When to Use Override and New Keywords (C# Programming Guide)

    https://msdn.microsoft.com/en-us/library/ms173153.aspx In C#, a method in a derived class can have t ...

  2. 【转】ACM 2567 -- 树的Prufer编码

    本文介绍北京大学ACM网站2567号题目的解法.介绍部分基本翻译自网站上的题目介绍. 题目介绍:    给定一棵各节点编号为整数1,2,3...n的树(例如,无环连通图),其Prufer编码(Pruf ...

  3. MySQL max_connections 总是 214 。不能设大了? max_connections = 214

    MySQL max_connections 总是 214 .不能设大了? centos7 mariadb 修改 max_connections 总是214 It was indeed limits s ...

  4. PCB C# MongoDB 查询(SQL,NOSQL,C#对比)

    一.准备阶段 1.查询数据清单准备 2.这里先将SQL语句执行顺序列出来,方便后面语句对比更好理解 ()SELECT ()DISTINCT ()<Top Num> <select l ...

  5. 当下较热web前端技术汇总

    Web前段技术发展很快,主流技术日新月异,想想自己刚毕业那会用的asp技术,现在已经很少有主流网站在使用了.再到后来的J2EE框架,然后SpringMVC大行其道,但是最近各种js框架被广为传播,Ht ...

  6. Context的正确使用

    一.Context的作用 Context的最大作用就是我们可以通过传递它来获得其他Activity或Application的相关资源和方法,它就相当于它们的引用,我们通过引用来获得对象的封装,这也是我 ...

  7. [Luogu 1052] noip 05 过河

    [Luogu 1052] noip 05 过河 题目描述 在河上有一座独木桥,一只青蛙想沿着独木桥从河的一侧跳到另一侧.在桥上有一些石子,青蛙很讨厌踩在这些石子上.由于桥的长度和青蛙一次跳过的距离都是 ...

  8. Android:EditText属性大全

    一.inputType属性inputType属性在EditText输入值时启动的虚拟键盘的风格有着重要的作用.比如有时需要虚拟键盘只为字符或只为数字. <span style="fon ...

  9. Coursera公开课-Machine_learing:编程作业2

    第三周编程作业:Logistic Regression 代码包在gitlab上:https://gitlab.com/luntai/Machine_Learning

  10. 获取qq音乐json数据---某课网音乐app学习

    移动端qq音乐地址:https://m.y.qq.com/ .抓取QQ音乐数据 请求首页时,有如下链接,回调了jsonp https://c.y.qq.com/splcloud/fcgi-bin/p. ...