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 fooling at 2009-09-14 14:03:19 on Problem 2632
#include<iostream>
#include<string>
using namespace std;

struct robot
{
	int x,y;
	char orientation;
}r[101];

struct operation
{
	int id,repeat;char op;
}o[101];


int main()
{	
	int cas,i,j,k,id,repeat,A,B,N,M;
	cin>>cas;
	char op;
	while(cas--)
	{
		cin>>A>>B;
		cin>>N>>M;
		for(i=1;i<=N;i++)
		{
			cin>>r[i].x>>r[i].y>>r[i].orientation;
		}
		int f=0;
		for(j=1;j<=M;j++)
		{
			cin>>o[j].id>>o[j].op>>o[j].repeat;
		}
		for(j=1;j<=M;j++)
		{
					id=o[j].id,op=o[j].op,repeat=o[j].repeat;
					if(op=='F')
					{
							if(r[id].orientation=='W')
							{
								for(k=1;k<=N;k++)
								{
									if(k!=id&&r[id].y==r[k].y&&r[id].x-r[k].x>0&&r[id].x-r[k].x<=repeat)
									{
										f=2;
									    printf("Robot %d crashes into robot %d\n",id,k);
										break;
									}
								}
								if(f==2)	break;
								r[id].x-=1*repeat;
								if(r[id].x<1)
								{
									f=1;
									printf("Robot %d crashes into the wall\n",id);
									break;
								}
								
							}
							else if(r[id].orientation=='E')
							{
								for(k=1;k<=N;k++)
								{
									if(k!=id&&r[id].y==r[k].y&&r[k].x-r[id].x>0&&r[k].x-r[id].x<=repeat)
									{
										f=2;
									    printf("Robot %d crashes into robot %d\n",id,k);
										break;;
									}
								}
								if(f==2)	break;
								r[id].x+=1*repeat;
								if(r[id].x>A)
								{
									printf("Robot %d crashes into the wall\n",id);
									f=1;
										break;
								}
							}
							else if(r[id].orientation=='N')
							{
								for(k=1;k<=N;k++)
								{
									if(k!=id&&r[id].x==r[k].x&&r[k].y-r[id].y>0&&r[k].y-r[id].y<=repeat)
									{
										f=2;
									    printf("Robot %d crashes into robot %d\n",id,k);
										break;
									}
								}
								if(f==2)	break;
								r[id].y+=1*repeat;
								if(r[id].y>B)
								{
									printf("Robot %d crashes into the wall\n",id);
									f=1;
									break;
								}
							}
							else if(r[id].orientation=='S')
							{
								for(k=1;k<=N;k++)
								{
									if(k!=id&&r[id].x==r[k].x&&r[id].y-r[k].y>0&&r[id].y-r[k].y<=repeat)
									{
										f=2;
									    printf("Robot %d crashes into robot %d\n",id,k);
										break;
									}
								}
								if(f==2)	break;
								r[id].y-=1*repeat;
								if(r[id].y<1)
								{
									printf("Robot %d crashes into the wall\n",id);
									f=1;
										break;
								}
							}
					}//end F
					else if(op=='L')
					{
							if(repeat%4==1)
							{
									if(r[id].orientation=='W')
									{
										r[id].orientation='S';
									}
									else if(r[id].orientation=='S')
									{
										r[id].orientation='E';
									}
									else if(r[id].orientation=='E')
									{
										r[id].orientation='N';
									}
									else if(r[id].orientation=='N')
									{
										r[id].orientation='W';
									}
							}
							else if(repeat%4==2)
							{
									if(r[id].orientation=='W')
									{
										r[id].orientation='E';
									}
									else if(r[id].orientation=='S')
									{
										r[id].orientation='N';
									}
									else if(r[id].orientation=='E')
									{
										r[id].orientation='W';
									}
									else if(r[id].orientation=='N')
									{
										r[id].orientation='S';
									}
							}
							else if(repeat%4==3)
							{
									if(r[id].orientation=='W')
									{
										r[id].orientation='N';
									}
									else if(r[id].orientation=='S')
									{
										r[id].orientation='W';
									}
									else if(r[id].orientation=='E')
									{
										r[id].orientation='S';
									}
									else if(r[id].orientation=='N')
									{
										r[id].orientation='E';
									}
							}
					}
					else if(op=='R')
					{
							if(repeat%4==1)
							{
									if(r[id].orientation=='W')
									{
										r[id].orientation='N';
									}
									else if(r[id].orientation=='S')
									{
										r[id].orientation='W';
									}
									else if(r[id].orientation=='E')
									{
										r[id].orientation='S';
									}
									else if(r[id].orientation=='N')
									{
										r[id].orientation='E';
									}
							}
							else if(repeat%4==2)
							{
									if(r[id].orientation=='W')
									{
										r[id].orientation='E';
									}
									else if(r[id].orientation=='S')
									{
										r[id].orientation='N';
									}
									else if(r[id].orientation=='E')
									{
										r[id].orientation='W';
									}
									else if(r[id].orientation=='N')
									{
										r[id].orientation='S';
									}

							}
							else if(repeat%4==3)
							{
									if(r[id].orientation=='W')
									{
										r[id].orientation='S';
									}
									else if(r[id].orientation=='S')
									{
										r[id].orientation='E';
									}
									else if(r[id].orientation=='E')
									{
										r[id].orientation='N';
									}
									else if(r[id].orientation=='N')
									{
										r[id].orientation='W';
									}
							}
					}
		}
		if(f==0)cout<<"OK"<<endl;
	}
	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