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?why??广搜。

Posted by sailors at 2006-10-20 13:11:31 on Problem 2935
#include<iostream.h>
#include<string.h>

struct Node 
{
	int x,y;
	int step;
	char s[50];
};
Node a[500];

int mark[7][7];
int wall[3][4];
int x1,y1,x2,y2;
int front,end;
int main()
{
	int i,j;
	int x,y;
	int xx1,yy1,xx2,yy2;
	while(cin>>y1>>x1)
	{
		memset(mark,0,sizeof(mark));
		for(i=0;i<300;i++)
		{
			a[i].step=0;
			for(j=0;j<40;j++)
			{
				a[i].s[j]='9';
			}
			a[i].s[40]='\0';
		}
		if(x1==0&&y1==0)break;
		cin>>y2>>x2;
		for(i=0;i<3;i++)
		{
			//for(j=0;j<4;j++)
			{
				cin>>wall[i][1]>>wall[i][0]>>wall[i][3]>>wall[i][2];
				wall[i][0]=wall[i][0]<wall[i][2]?wall[i][0]:wall[i][2];
				wall[i][1]=wall[i][1]<wall[i][3]?wall[i][1]:wall[i][3];
			}
		}
		front=end=0;
		a[0].x=x1;
		a[0].y=y1;
		a[0].step=1;
		mark[x1][y1]=1;
		end++;
		while(front!=end)
		{
			//front++;
			x=a[front].x;
			y=a[front].y;
			if(x==x2&&y==y2)
			{
				for(i=0;i<=40;i++)
				{
					if(a[front].s[i]!='9')cout<<a[front].s[i];
				}
			///////	cout<<a[front].s<<endl;
				cout<<endl; 
				break;
			}
			
			//E;
			x1=x;
			y1=y+1;
			xx1=x-1;
			yy1=y;
			xx2=x;
			yy2=y;
			if(y1<=6)
			{
				int flag=1;
				for(i=0;i<3;i++)
				{
					if(xx1>=wall[i][0]&&xx1<=wall[i][2]&&yy1>=wall[i][1]&&yy1<=wall[i][3]&&xx2>=wall[i][0]&&xx2<=wall[i][2]&&yy2>=wall[i][1]&&yy2<=wall[i][3])
					{
						flag=0;
						break;
					}
					
				}
				if(flag==1)
				{
					if(mark[x1][y1]==0)
					{
						a[end].x=x1;
						a[end].y=y1;
						mark[x1][y1]=1;
						a[end].step=a[front].step+1;
						strcpy(a[end].s,a[front].s);
						a[end].s[a[front].step]='E';
						end++;
					}
					
				}
				//N
				x1=x-1;
				y1=y;
				xx1=x-1;
				yy1=y-1;
				xx2=x-1;
				yy2=y;
				if(x1>=1)
				{
					int flag=1;
					for(i=0;i<3;i++)
					{
						if(xx1>=wall[i][0]&&xx1<=wall[i][2]&&yy1>=wall[i][1]&&yy1<=wall[i][3]&&xx2>=wall[i][0]&&xx2<=wall[i][2]&&yy2>=wall[i][1]&&yy2<=wall[i][3])
						{
							flag=0;
							break;
						}
						
					}
					if(flag==1)
					{
						if(mark[x1][y1]==0)
						{
							a[end].x=x1;
							a[end].y=y1;
							mark[x1][y1]=1;
							a[end].step=a[front].step+1;
							strcpy(a[end].s,a[front].s);
							a[end].s[a[front].step]='N';
							end++;
							
						}
					}
					
				}
				//W
				x1=x;
				y1=y-1;
				xx1=x-1;
				yy1=y-1;
				xx2=x;
				yy1=y-1;
				if(y1>=1)
				{
					int flag=1;
					for(i=0;i<3;i++)
					{
						if(xx1>=wall[i][0]&&xx1<=wall[i][2]&&yy1>=wall[i][1]&&yy1<=wall[i][3]&&xx2>=wall[i][0]&&xx2<=wall[i][2]&&yy2>=wall[i][1]&&yy2<=wall[i][3])
						{
							flag=0;
							break;
						}
						
					}
					if(flag==1)
					{
						if(mark[x1][y1]==0)
						{
							a[end].x=x1;
							a[end].y=y1;
							mark[x1][y1]=1;
							a[end].step=a[front].step+1;
							strcpy(a[end].s,a[front].s);
							a[end].s[a[front].step]='W';
							end++;
							
						}
					}
				}
				//S
				x1=x+1;
				y1=y;
				xx1=x;
				yy1=y-1;
				xx2=x;
				yy2=y;
				if(x1<=6)
				{
					int flag=1;
					for(i=0;i<3;i++)
					{
						if(xx1>=wall[i][0]&&xx1<=wall[i][2]&&yy1>=wall[i][1]&&yy1<=wall[i][3]&&xx2>=wall[i][0]&&xx2<=wall[i][2]&&yy2>=wall[i][1]&&yy2<=wall[i][3])
						{
							flag=0;
							break;
						}
					}
					if(flag==1)
					{
						if(mark[x1][y1]==0)
						{
							a[end].x=x1;
							a[end].y=y1;
							mark[x1][y1]=1;
							a[end].step=a[front].step+1;
							strcpy(a[end].s,a[front].s);
							a[end].s[a[front].step]='S';
							end++;
						}
					}
				}
			}
			front++;
		}
	}
	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