在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
又是细节啊,结束条件判错了,导致没有全部搜完就结束了,这个错误,检查了好几遍都没发现,终于找AC代码对拍数据,发现了。。。 1 #include <stdio.h> 2 #include <string.h> 3 int p[101][101],b,w,n,bnu,wnu,bb,ww,sum,z; 4 int x[4] = {0,0,-1,1}; 5 int y[4] = {1,-1,0,0}; 6 void dfs(int r,int c) 7 { 8 sum ++; 9 int i; 10 for(i = 0;i <= 3;i ++) 11 { 12 if(r+x[i] <= n&&r+x[i] >= 1&&c+y[i]>=1&&c+y[i]<=n) 13 { 14 if(!p[r+x[i]][c+y[i]]) 15 { 16 p[r+x[i]][c+y[i]] = 3; 17 dfs(r+x[i],c+y[i]); 18 } 19 else if(p[r+x[i]][c+y[i]] == 1) 20 { 21 bb = 1; 22 } 23 else if(p[r+x[i]][c+y[i]] == 2) 24 { 25 ww = 1; 26 } 27 if(bb&&ww) 28 {z = 1;} 29 } 30 } 31 return ; 32 } 33 int main() 34 { 35 int i,j,sv,ev; 36 while(scanf("%d",&n)!=EOF) 37 { 38 bnu = wnu = 0; 39 for(i = 1;i <= n;i ++) 40 for(j = 1;j <= n;j ++) 41 p[i][j] = 0; 42 if(!n) break; 43 scanf("%d%d",&b,&w); 44 for(i = 1;i <= b;i ++) 45 { 46 scanf("%d%d",&sv,&ev); 47 p[sv][ev] = 1; 48 } 49 for(i = 1;i <= w;i ++) 50 { 51 scanf("%d%d",&sv,&ev); 52 p[sv][ev] = 2; 53 } 54 for(i = 1;i <= n;i ++) 55 { 56 for(j = 1;j <= n;j ++) 57 { 58 bb = ww = 0; 59 sum = 0; 60 z = 0; 61 if(!p[i][j]) 62 { 63 p[i][j] = 3; 64 dfs(i,j); 65 if(!z) 66 { 67 if(bb&&!ww) 68 bnu += sum; 69 else if(ww&&!bb) 70 wnu += sum; 71 } 72 } 73 } 74 } 75 if(bnu == wnu) 76 { 77 printf("Draw\n"); 78 } 79 else if(bnu > wnu) 80 { 81 printf("Black wins by %d\n",bnu-wnu); 82 } 83 else if(wnu > bnu) 84 { 85 printf("White wins by %d\n",wnu-bnu); 86 } 87 } 88 return 0; 89 } |
请发表评论