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

每个墙或者门的起点是不是一定是整数啊?帮帮忙,看看这个怎么老是WRONG ANSWER?

Posted by wcm at 2004-11-16 21:18:54 on Problem 2049
#include	<stdlib.h>
#include	<stdio.h>

int
main()
{int i,j,x,y,xx,yy,d,t,m,n,a[200][200][4],went[200][200],p[4][2]={{0,1},{1,0},{0,-1},{-1,0}},h[40000],step,flag,k,minx,miny,maxx,maxy;
long result,sum;
float x1,y1;
scanf("%d%d",&m,&n);
while ((m!=-1)&&(n!=-1))
{memset(a,0,160000*sizeof(int));
minx=200;miny=200;maxx=0;maxy=0;
for (i=0;i<m;i++  )
{scanf("%d%d%d%d",&x,&y,&d,&t);
if ( x>maxx ) maxx=x;if ( x<minx ) minx=x;
if ( y>maxy ) maxy=y;if ( y<miny ) miny=y;
if (d==0)
  for ( j=0;j<t;j++)  {a[x][y][2]=1;a[x][y-1][0]=1;x++;}
   else   for ( j=0;j<t;j++ ) {a[x][y][3]=1;a[x-1][y][1]=1;y++;}
}
for ( i=0;i<n;i++ )
    {scanf("%d%d%d",&x,&y,&d);
     if ( d==0)  {a[x][y][2]=2;a[x][y-1][0]=2;}
     else {a[x][y][3]=2;a[x-1][y][1]=2;}
    }
scanf("%f%f",&x1,&y1);
x=x1;y=y1;
step=0;h[step]=0;flag=0;k=0;sum=0;result=50000;
memset(went,0,40000*sizeof(int));
while (step>=0)
{
if ( k>3 )   {step--;k=h[step];went[x][y]=0;x=x-p[k][0];y=y-p[k][1];
		  if ( a[x][y][k]==2 ) sum--;
		  k++;
		  }
else   {xx=x+p[k][0];yy=y+p[k][1];
	   if (((a[x][y][k]==0)||(a[x][y][k]==2)) && (went[xx][yy]==0))
		 { went[x][y]=1;
		   if ( a[x][y][k]==2 ) sum++;
		   if (xx>=maxx||xx<minx||yy>=maxy||yy<miny) {flag=1;
					if (sum<result)   result=sum;
					if ( a[x][y][k]==2 ) sum--;}
		   else {
		   x=xx;y=yy;h[step]=k;step++;k=-1;}
		 }
	   k++;
	  }
}
if ( flag==0 ) 	printf("%d\n",-1);
else printf("%d\n",result);
scanf("%d%d",&m,&n);
}
return 1;
}

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