【codeforces 515B】Drazil and His Happy Friends
【题目链接】: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的更多相关文章
- 【codeforces 515D】Drazil and Tiles
[题目链接]:http://codeforces.com/contest/515/problem/D [题意] 给你一个n*m的格子; 然后让你用1*2的长方形去填格子的空缺; 如果有填满的方案且方案 ...
- 【codeforces 515C】Drazil and Factorial
[题目链接]:http://codeforces.com/contest/515/problem/C [题意] 定义f(n)=n这个数各个位置上的数的阶乘的乘积; 给你a; 让你另外求一个不含0和1的 ...
- 【codeforces 515A】Drazil and Date
[题目链接]:http://codeforces.com/contest/515/problem/A [题意] 每次只能走到相邻的四个格子中的一个; 告诉你最后走到了(a,b)走了多少步->s ...
- 【codeforces 516B】Drazil and Tiles
题目链接: http://codeforces.com/problemset/problem/516/B 题解: 首先可以得到一个以‘.’为点的无向图,当存在一个点没有边时,无解.然后如果这个图边双联 ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
随机推荐
- jQuery Uploadify在ASP.NET MVC3中的使用
1.Uploadify简介 Uploadify是基于jQuery的一种上传插件,支持多文件.带进度条显示上传,在项目开发中常被使用. Uploadify官方网址:http://www.uploadif ...
- 启动Tomcat任何程序都报错
启动Tomcat出现: Cannot publish to the server because it is missing its runtime environment. 可能是servers中不 ...
- 洛谷 P3377 模板左偏树
题目:https://www.luogu.org/problemnew/show/P3377 左偏树的模板题: 加深了我对空 merge 的理解: 结构体的编号就是原序列的位置. 代码如下: #inc ...
- 【转载】基于AFNetWorking3.0的图片缓存分析
原文出处: Yasin的简书 理论 不喜欢理论的可以直接跳到下面的Demo实践部分 缓存介绍 缓存按照保存位置可以分为两类:内存缓存.硬盘缓存(FMDB.CoreData…).我们常说的网络请求缓存包 ...
- vi编辑文件保存后,提示“Can't open file for writing Press ENTER or type command to continue”
在linux上使用vi命令修改或者编辑一个文件内容的时候,最后发现使用<Esc+:+wq!>无法保存退出,却出现,如下提示: E212: Can't open file for writi ...
- 清北刷题班day3 morning
P99zhx: 竞赛时间:???? 年?? 月?? 日??:??-??:??题目名称 a b c名称 a b c输入 a.in b.in c.in输出 a.out b.out c.out每个测试点时限 ...
- node.js安装步骤
首先这是node.js的官网:https://nodejs.org/en/ 截至2017年12月9日,node更新在8.9.3该版本,建议开发人员下载6.0以上版本,8以上不是很稳定! 如果有其他需 ...
- Perforce 的基本使用教程
一.简介 P4是什么 二.基本使用方法 1.下载代码 下载最新代码 Get Latest Revision 下载指定commit代码 Get Revision 2. 检出代码 选择指定目录,右键 Ch ...
- Android 基础知识图谱
四大组件 Activity Service BroadcastReceiver ContentProvider Application 常用组件 Fragment RecyclerView WebVi ...
- JS——offset
1.offsetWidth.offsetHeight返回盒子宽度和高度,包括padding与border,不包括margin 2.offsetLeft.offsetTop返回盒子距离定位盒子的x轴方向 ...