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

16MS C/C++ 代码

Posted by lz1 at 2010-09-14 19:06:07 on Problem 3194
#include <stdio.h>
#include <string.h>
const int L=101;
const int d[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
int a[L][L];
int n,t,count;
bool sign;
//char c[100];

void dfs(int x,int y){
    a[x][y]=n;
    count++;
    for (int i=0;i<=3;i++){
        int xn=x+d[i][0],yn=y+d[i][1];
        if (xn<1||yn<1||xn>n||yn>n||a[xn][yn]!=t)continue;
        dfs(xn,yn);
        }
    return ;
    }

int main(void){
    freopen ("3194.in","r",stdin);
    freopen ("3194.out","w",stdout);
    while (scanf ("%d",&n)!=EOF&&n){
          memset (a,0,sizeof (a));
          for (int i=1,x,y;i<n;i++)
              for (char d='a';d!='\n';d=getchar())
                  scanf ("%d%d",&x,&y),a[x][y]=i;
          /*for (int i=1;i<=n;i++){
              for (int j=1;j<=n;j++)
                  printf ("%d ",a[i][j]);
              printf ("\n");
              }*/
          sign=true;
          for (int i=1;i<=n;i++){
              for (int j=1;j<=n;j++)
                  if (a[i][j]<n){
                     count=0,t=a[i][j],dfs(i,j);
                     if (count!=n){sign=false;break;}
                     }
              if (!sign)break;
              }
          if (sign)printf ("good\n");
          else printf ("wrong\n");
          }
    return 0;
    }
提醒一行有时没有或超过n个。

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