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

小妹泣血告求wrong在哪???

Posted by 08huozhixin at 2008-04-05 10:25:17 on Problem 2632
#include<iostream>
using namespace std;
struct direction
{
	char d;
	int next;
	int first;
}d4[4];
void initdirection()
{
	int i;
	d4[0].d='N';
	d4[1].d='E';
	d4[2].d='S';
	d4[3].d='W';
	for(i=0;i<3;i++)
	{
		d4[i].next=i+1;
	}
	d4[3].next=0;
	for(i=3;i>1;i--)
	{
		d4[i].first=i-1;
	}
	d4[0].first=3;
}
class robot
{
    int r;
	int v;
	char rd;
	int d4n;
public:
	void clear();
	void set(int,int,char);
    void setd4n();
	int move(int,char,int,int,int,robot*,int,int&);
	int outcome(int,int,int,robot*,int,int&);
};
void robot::clear()
{
	r=0;
	v=0;
	rd='\0';
	d4n=0;
}
void robot::set(int r,int v,char rd)
{
	this->r=r;
	this->v=v;
	this->rd=rd;
}
void robot::setd4n()
{
	int i=0;
    while(d4[i].d!=rd)
	{
		i++;
	}
	d4n=i;
}
int robot::move(int rnum,char inum,int n,int A,int B,robot*robotarray,int rn,int &cior)
{
	int result;
    int p;
	p=d4n;
	int i;
    switch(inum)
	{
	    case 'L':
		    for(i=0;i<n;i++)
			{
				p=d4[p].first;
				rd=d4[p].d;
			}
			break;
        case 'R':
			for(i=0;i<n;i++)
			{
			    p=d4[p].next;
				rd=d4[p].d;
			}
			break;
        case 'F':
			{
			    for(i=0;i<n;i++)
				{
					switch(rd)
					{
					    case 'N':
							r++;
							result=outcome(rnum,A,B,robotarray,rn,cior);
							if(result!=0)
								return result;
							break;               
						case 'E':
							v++;
							result=outcome(rnum,A,B,robotarray,rn,cior);
                        	if(result!=0)
								return result;
							break;               
                        case 'S':
							r--;
							result=outcome(rnum,A,B,robotarray,rn,cior);
	                        if(result!=0)
								return result;
							break;               
						case 'W':
							v--;
							result=outcome(rnum,A,B,robotarray,rn,cior);
                         	if(result!=0)
								return result;
							break;               
					}
				}
			}
		    break;			
	}
    return 0;
}
int robot::outcome(int rnum,int A,int B,robot *robotarray,int rn,int &cior)
{
	int i;
	if((r<0||r>A)||(v<0||v>B))
	{	
	    return 1;
	}
    for(i=0;i<rn;i++)
	{
		if(i!=rnum-1&&robotarray[i].r==r&&robotarray[i].v==v)
		{
			cior=i+1;
			return 2;
		}		  
	}
	return 0;	
}
int main()
{
    initdirection();
	int num,A,B,rn,in,rnum,n,r,v;
	int i,j,k;
	char rd,inum;
	int result,rerobot,cior=-1;
    robot robotarray[100];
    cin>>num;	
	for(i=0;i<num;i++)
	{
        cin>>B>>A>>rn>>in;		
        for(j=0;j<rn;j++)
		{
			cin>>v>>r>>rd;
			robotarray[j].set(r,v,rd); 
			robotarray[j].setd4n();	
		}
		for(j=0;j<in;j++)
		{
            cin>>rnum>>inum>>n;
			result=robotarray[rnum-1].move(rnum,inum,n,A,B,robotarray,rn,cior);
			if(result!=0)
			{
				k=j;
				rerobot=rnum;
				break;
			}
		}
		if(result==0)
			cout<<"OK"<<endl;
		else
		{
			for(j=k+1;j<in;j++)
                cin>>rnum>>inum>>n;
			switch(result)
			{
			    case 1:cout<<"Robot "<<rerobot<<" crashes into the wall"<<endl;break;
				case 2:cout<<"Robot "<<rerobot<<" crashes into robot "<<cior<<endl;break;
			}
		}
       for(i=0;i<rn;i++)
	   {
		   robotarray[i].clear();
	   }
	   result=-1;rerobot=-1;cior=-1;
	}
	return 1;
}

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