您的位置:首页 > 移动开发

Codeforces Round #292 (Div. 2)——B——Drazil and His Happy Friends

2015-03-19 13:00 387 查看
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

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
int n,m,h,g,x;
int a[1100],b[1100];
int main()
{
while(~scanf("%d%d",&n,&m)){
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
scanf("%d",&h);
for(int i = 1; i <= h ; i++){
scanf("%d",&x);
a[x] = 1;
}
scanf("%d",&g);
for(int i = 1; i <= g; i++){
scanf("%d",&x);
b[x] = 1;
}
int t = max(n,m);
for(int i = 0 ; i <= t*1000; i++){
if(a[i%n] == 1){
b[i%m] = 1;
continue;
}
if(b[i%m] == 1)
a[i%n] = 1;
}
int flag  = 0;
for(int i = 0; i < n; i++){
if(a[i] == 0) flag = 1;
}
for(int i = 0; i < m ; i++){
if(b[i] == 0 ) flag = 1;
}
if(flag) printf("No\n");
else printf("Yes\n");
}
return 0;
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: