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

Re:why wa ????

Posted by xinghun4 at 2007-09-12 16:16:34 on Problem 3194
In Reply To:why wa ???? Posted by:xinghun4 at 2007-09-11 17:00:02
> #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;
> }
在search(i,&x,&y);
后加个grid[x][y]=0
就ac啦,晕晕晕

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