1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
#include <iostream> #include <cstdio> using namespace std; int main() { int r,c,tmp,res; int row,col; //FILE *fp; //fp=fopen("out.txt","w"); while(scanf("%d%d",&r,&c)) { if(r+c==0) break; if((r==1 || c==1) || r==0 || c==0) { printf("%d knights may be placed on a %d row %d column board.\n",r*c,r,c); //fprintf(fp,"%d knights may be placed on a %d row %d column board.\n",r*c,r,c); continue; } if((r==2 || c==2)) { if(r!=2) { col=r; row=2; } else { row=r; col=c; } tmp=col/2; if(tmp%2==0) { res=(tmp/2)*4; } else { res=(tmp/2+1)*4; } if(col%4==1) res+=2; printf("%d knights may be placed on a %d row %d column board.\n",res,r,c); //fprintf(fp,"%d knights may be placed on a %d row %d column board.\n",res,r,c); continue; } tmp=(r*c)/2; if(tmp*2== r*c) { printf("%d knights may be placed on a %d row %d column board.\n",tmp,r,c); //fprintf(fp,"%d knights may be placed on a %d row %d column board.\n",tmp,r,c); } else { printf("%d knights may be placed on a %d row %d column board.\n",tmp+1,r,c); //fprintf(fp,"%d knights may be placed on a %d row %d column board.\n",tmp+1,r,c); } } //fclose(fp); return 0; } |