CF round #292 解题报告
A题:
给出一个坐标(a,b),和走的步数,问有没有可能从(0,0)走这么多步刚好到达(a,b).
水题,结果还是wa了一次,没有考虑到a<0或者b<0的情况。
1 #include<cstdio> 2 int main() 3 { 4 int a,b,s; 5 while(scanf("%d%d%d",&a,&b,&s)!=EOF){ 6 if(a<0) 7 a=-a; 8 if(b<0) 9 b=-b; 10 if(a+b>s) 11 printf("NO\n"); 12 else{ 13 s=a+b-s; 14 if(s%2) 15 printf("No\n"); 16 else 17 printf("Yes\n"); 18 } 19 } 20 return 0; 21 }
B题:
主人公有n个男性朋友,为0到n-1,m个女性朋友,为0到m-1,有些朋友开心,有些不开心。
其中b个男性朋友是开心的,n-b个不开心,
g个女性朋友是开心的,m-g个不开心。
给出n,m,
b,和b个坐标
g,和g个坐标
操作:
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.
我是直接走一遍,最后再扫描一遍,检查是不是所有人都开心了。
1 #include<cstdio> 2 #include<cstring> 3 int boy[110]; 4 int girl[110]; 5 int main() 6 { 7 int n,m; 8 while(scanf("%d%d",&n,&m)!=EOF){ 9 memset(boy,0,sizeof(boy)); 10 memset(girl,0,sizeof(girl)); 11 int b,bb; 12 scanf("%d",&b); 13 for(int i=0;i<b;i++){ 14 scanf("%d",&bb); 15 boy[bb]=1; 16 } 17 int g,gg; 18 scanf("%d",&g); 19 for(int i=0;i<g;i++){ 20 scanf("%d",&gg); 21 girl[gg]=1; 22 } 23 int sum=n*m*n*m; 24 25 for(int i=0;i<sum;i++){ 26 if(boy[i%n]||girl[i%m]) 27 boy[i%n]=girl[i%m]=1; 28 } 29 bool flag=true; 30 for(int i=0;i<n;i++) 31 if(!boy[i]){ 32 flag=false; 33 break; 34 } 35 if(flag){ 36 for(int i=0;i<m;i++) 37 if(!girl[i]){ 38 flag=false; 39 break; 40 } 41 } 42 if(flag) 43 printf("Yes\n"); 44 else 45 printf("No\n"); 46 } 47 return 0; 48 }