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 yzhw9981 at 2009-04-17 13:42:38 on Problem 1104
# include <stdio.h>
# include <stdbool.h>
int w,h,t;
struct refer
{
     int t;
     int lx,ly;
     int rx,ry;
}data[102];
struct point
{
       int x,y;
       int t;
}res[102];
bool map[102][101][101];
bool tmap[102][101][101];
int num;
void printmap()
{
     int i,j,k;
     for(i=1;i<=t;i++)
     {
      for(j=1;j<=h;j++)
      {
       for(k=1;k<=w;k++)
        printf("%d",map[i][k][j]);
       printf("\n");
      }
      printf("\n\n");
     }
     system("pause");
}
void setmap1(int now,int lx,int ly,int rx,int ry)
{
     if(rx>=lx&&ry>=ly&&now<=t&&now>=1)
     {
        int i,j;
       for(i=lx;i<=rx;i++)
          for(j=ly;j<=ry;j++)
           map[now][1][j]=0;
        setmap1(now+1,lx+1,ly+1,rx-1,ry-1);
     }
     else return;
}
void setmap2(int now,int lx,int ly,int rx,int ry)
{
     if(rx>=lx&&ry>=ly&&now<=t&&now>=1)
     {
        int i,j;
        for(i=lx;i<=rx;i++)
          for(j=ly;j<=ry;j++)
           map[now][i][j]=0;
        setmap2(now-1,lx+1,ly+1,rx-1,ry-1);
     }
     else return;
}
int chk(int now,int *x,int *y)
{
    int i,j,count=0;
    for(i=1;i<=w;i++)
       for(j=1;j<=h;j++)
         if(map[now][i][j])
         {
          if(count>1) return 0;
          count++;
          *x=i;
          *y=j;
         }
    if(count==0) return -1;/*无法从本状态到下个状态*/ 
    else return 1;/*只有一条通路到下个状态*/ 
}           
bool canfind(int i,int j,int now)
{
     if(map[now][i][j]) return 1;
     if(i+1<=w&&map[now][i+1][j]) return 1;
     if(i-1>=1&&map[now][i-1][j]) return 1;
     if(j+1<=h&&map[now][i][j+1]) return 1;
     if(j-1>=1&&map[now][i][j-1]) return 1;
     return 0;
}  
void resetmap(int now)
{
     int i,j;
     for(i=1;i<=w;i++)
       for(j=1;j<=h;j++)
         if(map[now][i][j])
         {
           if(canfind(i,j,now-1)&&canfind(i,j,now+1)) tmap[now][i][j]=1;
         }
}     
bool check()
{
     int i,j,k;
     for(k=1;k<=t;k++)
       for(i=1;i<=w;i++)
         for(j=1;j<=h;j++)
           if(map[k][i][j]!=tmap[k][i][j])
             return 0;
     return 1;
}                 
int main()
{
    int casenum=1;
    while(1)
    {
      scanf("%d %d %d",&w,&h,&t);
      memset(map,1,sizeof(map));
      if(!w&&!h&&!t) break;
      int i,j;
      scanf("%d",&num);
      for(i=1;i<=num;i++)
      {
            scanf("%d %d %d %d %d",&data[i].t,&data[i].lx,&data[i].ly,&data[i].rx,&data[i].ry);
      }
      /*-------------------buildmap----------------------------------*/
      for(i=1;i<=num;i++)
      {
       setmap1(data[i].t,data[i].lx,data[i].ly,data[i].rx,data[i].ry);
       setmap2(data[i].t,data[i].lx,data[i].ly,data[i].rx,data[i].ry);
       
      }
      /*-------------------judge-------------------------------------*/
      memset(tmap,0,sizeof(tmap));
       while(1)
       {
         for(i=1;i<=t;i++) resetmap(i);
         if(check()) break;
          int k;
          for(k=1;k<=t;k++)
            for(i=1;i<=w;i++)
              for(j=1;j<=h;j++)
                map[k][i][j]=tmap[k][i][j];
         memset(tmap,0,sizeof(tmap));
       }
      int count=0;
      bool flag=1;
      for(i=1;i<=t;i++)
      {
       int x,y;
       int jud=chk(i,&x,&y);
       if(jud==1)
       {
           res[++count].x=x;
           res[count].y=y;
           res[count].t=i;
       }
       else if(jud==-1)
       {
           flag=0;
           break;
       }
      }
      printf("Robbery #%d:\n",casenum++);
      if(!flag) printf("The robber has escaped.\n\n");
      else if(!count) printf("Nothing known.\n\n");
      else
      {
          for(i=1;i<=count;i++) 
             printf("Time step %d: The robber has been at %d,%d.\n",i,res[i].x,res[i].y);
          printf("\n");
      }
    }
    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