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

哪里错了呢 请赐教

Posted by hwl20063338 at 2008-11-29 01:02:47 on Problem 2632
#include<iostream>
using namespace std;

int row,col;
int map[110][110];
int loc[110][2];
int dir[110];
int oriention[4][2]={{1,0},{0,1},{-1,0},{0,-1}};

int forward(int o,int re)
{
	int x,y;
	x=loc[o][0];
	y=loc[o][1];
	int k=oriention[dir[o]][0];
	int j=oriention[dir[o]][1];
	map[x][y]=0;
	for(int i=1;i<=re;i++)
	{
		x+=k;
		y+=j;
		if(x<=0||x>=row+1||y<=0||y>=col+1)//zhuang qiang
		{
			cout<<"Robot "<<o<<" crashes into the wall"<<endl;
			return 0;
		}
		if(map[x][y])//zhuang jiqi
		{
			cout<<"Robot "<<o<<" crashes into robot "<<map[x][y]<<endl;
			return 0;
		}
	}
	loc[o][0]=x;
	loc[o][1]=y;
	map[x][y]=o;//成功移到新位置
	return 1;
}

int emuluator(int o,char c,int re)
{
	switch(c)
	{
	case 'L':dir[o]=(dir[o]+re)%4;return 1;
	case 'R':dir[o]=(dir[o]-re+4)%4;return 1;
	case 'F':return forward(o,re);
	default: return 0;
	}
}

int main()
{
	int table[130];
	table['E']=0;
	table['N']=1;
	table['W']=2;
	table['S']=3;
	int cases;
	int num,mand;
	int i;
	cin>>cases;
	while(cases--)
	{
		cin>>row>>col;
		cin>>num>>mand;
		char c;
		memset(map,0,sizeof(map));
		memset(loc,0,sizeof(loc));
		memset(dir,0,sizeof(dir));
		for(i=1;i<=num;i++)
		{
			cin>>loc[i][0]>>loc[i][1]>>c;
			dir[i]=table[c];
			map[loc[i][0]][loc[i][1]]=i;
		}
		int f=1;
		int order[110];
		int repeat[110];
		char c1[110];
		for(i=1;i<=mand;i++)
		{
			cin>>order[i]>>c1[i]>>repeat[i];
		}
		for(i=1;i<=mand;i++)
		{
			if(f)
				f=emuluator(order[i],c1[i],repeat[i]);
			else
				break;
		}
		if(f)
			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