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 Damonbaby at 2011-05-05 22:36:00 on Problem 2312
#include <cstdio>
#include <string.h>
#include <queue>
using namespace std;
#define M 400
char map[M][M];
int vis[M][M];
int movex[4]={1,-1,0,0};
int movey[4]={0,0,-1,1};
int n,m;
int ex,ey;
int bfs(int x,int y)
{
	queue<int> q;
	int i,xx,yy;
	q.push(x);
	q.push(y);
	vis[x][y]=0;
	while(!q.empty())
	{
		x=q.front();
		q.pop();
		y=q.front();
		q.pop();
		if(x==ex&&y==ey)
			return vis[x][y];
		for(i=0;i<4;i++)
		{
			xx=x+movex[i];
			yy=y+movey[i];
			if(xx>=0&&xx<n&&yy>=0&&yy<m&&map[xx][yy]!='S'&&map[xx][yy]!='R')
			{
				if(map[xx][yy]=='B')
				{
					if(vis[xx][yy]>vis[x][y]+2)
					{	
						vis[xx][yy]=vis[x][y]+2;
						q.push(xx);
						q.push(yy);
					}
				}
				else 
				{
					if(vis[xx][yy]>vis[x][y]+1)
					{
						vis[xx][yy]=vis[x][y]+1;
						q.push(xx);
						q.push(yy);
					}
				}
			}
		}
	}
	return -1;
}
int main()
{
	int i,stx,sty,j,min;
	while(scanf("%d%d",&n,&m)!=EOF,n+m)
	{
		getchar();
		for(i=0;i<n;i++)
		{
			for(j=0;j<m;j++)
			{
				vis[i][j]=21000000;
				scanf("%c",&map[i][j]);
				if(map[i][j]=='T')
					ex=i,ey=j;
				if(map[i][j]=='Y')
					stx=i,sty=j;
			}
			getchar();
		}
		min=bfs(stx,sty);
		if(min!=-1)
			printf("%d\n",min);
		else
			printf("-1\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