Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
why wa ????#include<stdio.h> #include<iostream> int n,num,t; int grid[100][100]; void search(int k,int *x,int *y) { int i,j; for(i=1;i<=n;i++) for(j=1;j<=n;j++) if(grid[i][j]==k) {*x=i;*y=j;break;} } void go(int,int,int); void find(int k,int x,int y) { if(x<1||x>n||y<1||y>n) return ; if(grid[x][y]==k) { t++; grid[x][y]=0; go(k,x,y); } } void go(int k,int x,int y) { if(t==n) {num++;return ;} find(k,x-1,y); find(k,x,y-1); find(k,x+1,y); find(k,x,y+1); } int main() { int i,j,x,y; while(scanf("%d",&n)&&n) { for(i=1;i<=n;i++) for(j=1;j<=n;j++) grid[i][j]=n; for(i=1;i<=n-1;i++) for(j=1;j<=n;j++) { scanf("%d %d",&x,&y); grid[x][y]=i; } for(num=0,i=1;i<=n&&num<n;i++) { search(i,&x,&y); t=1; go(i,x,y); if(t<n) break; } if(num==n) printf("good\n"); else printf("wrong\n"); } system("pause"); return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator