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,求路过的大牛,小牛指教

Posted by liuhighway at 2011-03-22 23:02:11 on Problem 2632
#include<iostream>
#define max 1000
using namespace std;
int m,n;
struct node
{
	int x;
	int y;
	int dir[2];
	char ch;
}s[max];
struct com
{
	int r;
	int di;
	int re;
}t[max];
int visit[max][max];
void  chao( char c, int &x,int &y)
{
	switch(c)
	{
	case  'E': 
		{ x=1;y =0;}break;
	case 'W':
		{x=-1,y=0;}break;
	case 'N':
		{x=0;y=1;}break;
	case 'S':
		{x=0,y=-1;}break;
	}
}
void change( char c,char d ,int n,int &x,int  &y)//char c 原来 //char d 转
{
	int k=0;
		
	if(d=='L')
	{  
		if(c=='E') k=0;
		if(c=='W')k=2;
		if(c=='S')k=3;
		if(c=='N') k=1;
		int a[4][2]={{1,0}, {0,1},{-1,0},{0,-1}};	
		x= a[(k+n)%4][0];
		y= a[(k+n)%4][1];
	}
	else 
	{ 
		if(c=='E') k=0;
		if(c=='W')k=2;
		if(c=='S')k=1;
		if(c=='N') k=3;
		int b[4][2]={{1,0}, {0,-1},{-1,0},{0,1}};
		x= b[(k+n)%4][0];
		y= b[(k+n)%4][1];
	}
}			
	
int  right(int x,int y)
{
	if(x<=0||x>m||y<=0||y>n)
		return 1;
	else
	{
		if(visit[x][y]!=0)
			return 2;
		else
	return 0;
	}
}
	
int main()
{ 
	int i,comman,num,j;
	int ro1,ro2,ro3;
	int test;
	freopen("in.txt","r",stdin);
	scanf("%d",&test);
	while(test--)
	      
	{
		scanf("%d%d",&m,&n);         
	 scanf("%d%d",&num,&comman);
	    memset(visit,0,sizeof(visit));
	for(i=1;i<=num;i++)
	{
		scanf("%d%d %c",&s[i].x,&s[i].y,&s[i].ch);
				getchar();
		visit[s[i].x][s[i].y]=i;		
		chao(s[i].ch,s[i].dir[0],s[i].dir[1]);
		//cout<<s[i].dir[0]<<" "<<s[i].dir[1]<<endl;
	
	}
	int sign=0;
	for(i=0;i<comman;i++)
	{
		scanf("%d %c%d",&t[i].r,&t[i].di,&t[i].re);
		if(sign==0)
			{
		if(t[i].di!='F')
		{
			change(s[t[i].r].ch,t[i].di,t[i].re%4, s[t[i].r].dir[0], s[t[i].r].dir[1]);
			if( s[t[i].r].dir[0]==0&&s[t[i].r].dir[1]==-1)
			 s[t[i].r].ch='S';
			if( s[t[i].r].dir[0]==1&&s[t[i].r].dir[1]==0)
			 s[t[i].r].ch='E';
			if( s[t[i].r].dir[0]==-1&&s[t[i].r].dir[1]==0)
			 s[t[i].r].ch='W';
			if( s[t[i].r].dir[0]==0&&s[t[i].r].dir[1]==1)
			 s[t[i].r].ch='N';
		//	cout<<"change"<<" "<<s[t[i].r].ch<<endl;
		}
		else
		{
			
			for(j=0;j<t[i].re;j++)
			{
				if(sign==0)
				{
									
				visit[s[t[i].r].x][s[t[i].r].y]=0;
				s[t[i].r].x+=s[t[i].r].dir[0];
				s[t[i].r].y+=s[t[i].r].dir[1];
				
				//	cout<<"dir"<<s[t[i].r].dir[0]<<" "<<s[t[i].r].dir[1]<<endl;
					//	cout<<"robot and pos"<<endl;
			    // cout<<t[i].r<<" "<<s[t[i].r].x<<" "<<s[t[i].r].y<<endl;
			
				sign=right(s[t[i].r].x,s[t[i].r].y);
				if(sign ==1)
				ro1=t[i].r;	
				if(sign==2)				
				{ 
					ro2=t[i].r;
				  ro3=visit[s[t[i].r].x][s[t[i].r].y];
				}
            	
				    if(sign==0)				
					visit[s[t[i].r].x][s[t[i].r].y]=t[i].r;
				}
			}
			}
		}
		
	}
	if(sign==1)printf("Robot %d crashes into the wall\n",ro1);
		if(sign==2)	printf("Robot %d crashes into robot %d\n",ro2,ro3);

 if(sign==0)  printf("OK\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