Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

why wa ????

Posted by xinghun4 at 2007-09-11 17:00:02 on Problem 3194
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator