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

谁能帮我看看,老是WA?

Posted by ppk1515 at 2010-08-13 14:23:37 on Problem 1548
代码比较简单,我就不解释了,能给个错误测试数据也行。
#include "stdio.h"
int a[30][30];
int count=0;

void fun(int pi,int pj,int row,int col)
{
    a[pi][pj]=0;
    count--;
    while(1)
    {
           int hasCol=0,i=0,j=0;
           for(j=pj;j<=col;j++)
              if(a[pi][j]==1)
              {
                 pj=j;
                 a[pi][j]=0;
                 count--;
              }
           for(i=pi;i<=row;i++)
               if(a[i][pj]==1)
                 {
                   pi=i;hasCol=1;
                   a[i][pj]=0;
                   count--;
                 }
           if(0==hasCol)
           {
              for(i=pi+1;i<=row;i++)
              {
                  for(j=pj+1;j<=col;j++)
                     if(1==a[i][j])
                     {
                         pi=i;
                         pj=j;
                         break;
                     }
                  if(j<=col)break;
              }
              if(i>row)break;
           }
    }    
}
void init(int a[30][30])
{
    int i,j;
    for(i=1;i<=30;i++)
        for(j=1;j<=30;j++)
            a[i][j]=0;
}
int main()
{
    int i=0,j=0,row=-1,col=-1,fi,fj,robotCount=0;
    init(a);
    scanf("%d%d",&i,&j);
    while(i!=-1||j!=-1)
    {
        if(i==0&&j==0)
        {
           for(fi=1;fi<=row;fi++)
           {
               for(fj=1;fj<=col;fj++)
                   if(a[fi][fj]==1)
                   {
                       fun(fi,fj,row,col);
                       robotCount++;
                       break;
                   }
               if(0==count)break;
           }
           printf("%d\n",robotCount);

           init(a);
           row=-1;
           col=-1;
           count=0;
           robotCount=0;
        }
        else
        {
           a[i][j]=1;
           if(i>row)row=i;
           if(j>col)col=j;
           count++;
        }
        scanf("%d%d",&i,&j);
    }
    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