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

为什么总是runtime error,就算在增大100倍也一样,向各位大牛求助

Posted by shennong at 2012-08-21 16:04:39 on Problem 1324
#include<stdio.h>
#include<string.h>
#define blue 1
#define black 2
#define white -1
int vist[2500][2500],L,t,flag,opt[2500][2500];
struct node
{
   int xx,yy;
}snake[1000],dui[1000][100];
int m,n;
void bfs(int x,int y)//蛇头坐标
{
	struct node tem[10];
	int rear=0,front=0,i,j;
	dui[rear][1].xx=x;
	dui[rear][1].yy=y;
	for(i=2;i<=L;i++)
	{
		dui[rear][i].xx=snake[i].xx;
		dui[rear][i].yy=snake[i].yy;
	}
	opt[x][y]=0;//最短距离
	vist[x][y]=blue;//标记数组;
	front++;
	while(rear!=front)
	{
		for(i=1;i<=m;i++)
		{
			for(j=1;j<=n;j++)
			{
                if(vist[i][j]!=black)
				{
					vist[i][j]=white;
				}
			}
		}
		for(i=1;i<=L;i++)
		{
			tem[i].xx=dui[rear][i].xx;
			tem[i].yy=dui[rear][i].yy;
			if(vist[tem[i].xx][tem[i].yy]==white)
			{
			   vist[tem[i].xx][tem[i].yy]=blue;
			}
		}
		rear++;
		x=tem[1].xx;
		y=tem[1].yy;//蛇头坐标
		if(x==y&&x==1)
		{
			flag=1;
			t=opt[x][y];
			break;
		}
		if(vist[x+1][y]==white)
		{
			vist[x+1][y]=blue;
			opt[x+1][y]=opt[x][y]+1;
			dui[front][1].xx=x+1;
            dui[front][1].yy=y;
			for(i=2;i<=L;i++)
			{
				dui[front][i].xx=tem[i-1].xx;
				dui[front][i].yy=tem[i-1].yy;
			}
			front++;
		}
		if(vist[x-1][y]==white)
		{
			vist[x-1][y]=blue;
			opt[x-1][y]=opt[x][y]+1;
			dui[front][1].xx=x-1;
            dui[front][1].yy=y;
			for(i=2;i<=L;i++)
			{
				dui[front][i].xx=tem[i-1].xx;
				dui[front][i].yy=tem[i-1].yy;
			}
			front++;
		}
		if(vist[x][y+1]==white)
		{
			vist[x][y+1]=blue;
			opt[x][y+1]=opt[x][y]+1;
			dui[front][1].xx=x;
            dui[front][1].yy=y+1;
			for(i=2;i<=L;i++)
			{
				dui[front][i].xx=tem[i-1].xx;
				dui[front][i].yy=tem[i-1].yy;
			}
			front++;
		}
		if(vist[x][y-1]==white)
		{
			vist[x][y-1]=blue;
			opt[x][y-1]=opt[x][y]+1;
			dui[front][1].xx=x;
            dui[front][1].yy=y-1;
			for(i=2;i<=L;i++)
			{
				dui[front][i].xx=tem[i-1].xx;
				dui[front][i].yy=tem[i-1].yy;
			}
			front++;
		}
	}
	return ;
}
int main()
{
	int i,j,zong,K,x,y;
	for(zong=1;;zong++)
	{
		flag=0;
		memset(opt,0,sizeof(opt));
		memset(vist,0,sizeof(vist));
		scanf("%d%d%d",&m,&n,&L);
		if(m==n&&n==L&&L==0)  break;
		for(i=1;i<=m;i++)
		{
			for(j=1;j<=n;j++)
			{
				vist[i][j]=white;
			}
		}
		for(i=1;i<=L;i++)
		{
			scanf("%d %d",&snake[i].xx,&snake[i].yy);
			//map[snake[i].xx][snake[i].yy]=blue;
		}
		scanf("%d",&K);
		for(i=1;i<=K;i++)
		{
			scanf("%d %d",&x,&y);
			vist[x][y]=black;
		}
		bfs(snake[1].xx,snake[1].yy);
		if(flag==1)
		{
			printf("Case %d: %d\n",zong,t);
		}
		else
		{
			printf("Case %d: -1\n",zong);
		}
	}
	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