题目链接:http://codeforces.com/problemset/problem/515/B

题目意思:有 n 个 boy 和 m 个 girl,有 b 个 boy 和 g 个 girl (通过给出数组下标)是 happy的,规定每轮 dinner 中,派出编号为 i mod n 个男 和 i mod m 个女去。只要他们其中一个为 happy 时,另一个也会变得 happy,问最终所有男女是否都变得 happy。

  一步一步模拟就可以了。这个问题有一个难点,就是究竟要进行多少次才能判断有些男女无论如何都不会happy的。由于数据量不大,只有100。最坏的情况就是每一个男女都有机会组合,所以 100 * 100 次来控制次数就可以了。每次配完对都检查下是否每个男女都已经为 happy,以便尽早结束循环,不要再进行无谓的组合。

  开 virtual 做的,发现,为什么B比C更加少人做出来。。。(C是完全木有思路 - -)

  

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std; const int maxn = + ;
int boy[maxn], girl[maxn];
int n, m; int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif // ONLINE_JUDGE int b, g;
while (scanf("%d%d", &n, &m) != EOF) {
memset(boy, , sizeof(boy));
memset(girl, , sizeof(girl)); int in;
scanf("%d", &b);
for (int i = ; i < b; i++) {
scanf("%d", &in);
boy[in] = ;
}
scanf("%d", &g);
for (int i = ; i < g; i++) {
scanf("%d", &in);
girl[in] = ;
}
bool flag;
int stb = , stg = ;
int cnt = maxn*maxn;
while (cnt) {
flag = true;
stb %= n;
stg %= m;
if (boy[stb] || girl[stg]) { // 其中一个是happy的
boy[stb] = ;
girl[stg] = ;
}
// 检查男女两边是否都已经happy
for (int i = ; i < n; i++) {
if (!boy[i]) {
flag = false;
break;
}
}
for (int i = ; i < m; i++) {
if (!girl[i]) {
flag = false;
break;
}
}
if (flag)
break;
stb++;
stg++;
cnt--;
}
printf("%s\n", flag ? "Yes" : "No");
}
return ;
}

codeforces 515B. Drazil and His Happy Friends 解题报告的更多相关文章

  1. CodeForces 515B. Drazil and His Happy Friends

    B. Drazil and His Happy Friends time limit per test 2 seconds memory limit per test 256 megabytes in ...

  2. codeforces 814B.An express train to reveries 解题报告

    题目链接:http://codeforces.com/problemset/problem/814/B 题目意思:分别给定一个长度为 n 的不相同序列 a 和 b.这两个序列至少有 i 个位置(1 ≤ ...

  3. codeforces 558B. Amr and The Large Array 解题报告

    题目链接:http://codeforces.com/problemset/problem/558/B 题目意思:给出一个序列,然后找出出现次数最多,但区间占用长度最短的区间左右值. 由于是边读入边比 ...

  4. codeforces 514B. Han Solo and Lazer Gun 解题报告

    题目链接:http://codeforces.com/problemset/problem/514/B 题目意思:给出双头枪的位置(x0, y0),以及 n 个突击队成员的坐标.双头枪射击一次,可以把 ...

  5. codeforces 471C.MUH and House of Cards 解题报告

    题目链接:http://codeforces.com/problemset/problem/471/C 题目意思:有 n 张卡,问能做成多少种不同楼层(floor)的 house,注意这 n 张卡都要 ...

  6. codeforces C. Vasily the Bear and Sequence 解题报告

    题目链接:http://codeforces.com/problemset/problem/336/C 题目意思:给出一个递增的正整数序列 a1, a2, ..., an,要求从中选出一堆数b1, b ...

  7. codeforces A. Vasily the Bear and Triangle 解题报告

    题目链接:http://codeforces.com/problemset/problem/336/A 好简单的一条数学题,是8月9日的.比赛中没有做出来,今天看,从pupil变成Newbie了,那个 ...

  8. codeforces 820A. Mister B and Book Reading 解题报告

    题目链接:http://codeforces.com/problemset/problem/820/A 坑爹题目,坑爹题目,坑爹题目....汗 = =!  后台还110个 test 有个地方需要注意下 ...

  9. codeforces C. Inna and Huge Candy Matrix 解题报告

    题目链接:http://codeforces.com/problemset/problem/400/C 题目意思:给出一个n行m列的矩阵,问经过 x 次clockwise,y 次 horizontal ...

随机推荐

  1. webapp中的meta

    <!--开发后删除--> <meta http-equiv="Pragma" name="no-store" /><!--必须联网 ...

  2. 2015年12月01日 GitHub入门学习(二)手把手教你Git安装

    序:Mac与Linux中,Mac都预装了Git,各版本的Linux也都提供了Git的软件包.下面手把手教你Windows下的安装. 一.Git Windows GUI 下载地址 msysgit htt ...

  3. ajxa

    ajxa上传文件提交: ajxa跨域:http://www.cnblogs.com/sunxucool/p/3433992.html http://www.cnblogs.com/fsjohnhuan ...

  4. POJ 2452 Sticks Problem

    RMQ+二分....枚举 i  ,找比 i 小的第一个元素,再找之间的第一个最大元素.....                   Sticks Problem Time Limit: 6000MS ...

  5. Knockout.Js案例一Introduction

    </strong></p> <p>Last name: <strong data-bind="text:lastName ">tod ...

  6. MyEclipse 2013优化配置【转】

    作者:chszs,转载需注明.博客主页:http://blog.csdn.net/chszs MyEclipse 2013优化速度方案仍然主要有这么几个方面:去除无需加载的模块.取消冗余的配置.去除不 ...

  7. Linux学习:用yum安装php,httpd,mysql

    见鸟哥的linux私房菜电子版832页.

  8. HDU 5074 Hatsune Miku(2014鞍山赛区现场赛E题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5074 解题报告:给出一个长度为n的序列,例如a1,a2,a3,a4......an,然后这个序列的美丽 ...

  9. 瀑布流js排列

    var _px = document.getElementById("px"); var con=document.getElementById("content&quo ...

  10. SQLMAP脱裤

    之前就有一个朋友问,咋使用sqlmap脱裤.然后我丢了一个参数给他,他好像懵逼懵逼的.今天又有一个哥们儿在群里问,行吧.就直接教一下. 其实很简单. --dump这个参数就是用来脱裤的哟.如果你要拖整 ...