POJ-2632-Crashing Robots-模拟题

http://poj.org/problem?id=2632


坐标的n,m与编程的相反....

方向的N,S也要注意是相反的




#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <iostream>
using namespace std;  
__int64 inf=15;
double eps=0.000001;    

 int mp[105][105];
struct node
{
	int y,x;
	char  dir;
};
node robot[105];
int done;
int xx,yy;
void turnR(int who)
{
	if (robot[who].dir=='N') robot[who].dir='E';
else	if (robot[who].dir=='W') robot[who].dir='N';
else if (robot[who].dir=='S') robot[who].dir='W';
else	if (robot[who].dir=='E') robot[who].dir='S';
}
void turnl(int who)
{
 	if (robot[who].dir=='N') robot[who].dir='W';
else	if (robot[who].dir=='W') robot[who].dir='S';
else	if (robot[who].dir=='S') robot[who].dir='E';
else	if (robot[who].dir=='E') robot[who].dir='N';
}
void goford(int who)
{
		int x=robot[who].x;
		int y=robot[who].y;
	if (robot[who].dir=='S') 
	{
		if (x-1<=0)
		{printf("Robot %d crashes into the wall\n",who); done=1;return ;}
		else if (mp[x-1][y])
		{printf("Robot %d crashes into robot %d\n",who,mp[x-1][y]); done=1;return ;}
		else
		{mp[x][y]=0;robot[who].x--;mp[x-1][y]=who;}
	}
	if (robot[who].dir=='W') 
	{
		if (y-1<=0)
		{printf("Robot %d crashes into the wall\n",who); done=1;return ;}
		else if (mp[x][y-1])
		{printf("Robot %d crashes into robot %d\n",who,mp[x][y-1]); done=1;return ;}
		else
		{mp[x][y]=0;robot[who].y--;mp[x][y-1]=who;}
	}
	if (robot[who].dir=='N') 
	{
		if (x+1>yy)
		{printf("Robot %d crashes into the wall\n",who); done=1;return ;}
		else if (mp[x+1][y])
		{printf("Robot %d crashes into robot %d\n",who,mp[x+1][y]); done=1;return ;}
		else
		{mp[x][y]=0;robot[who].x++;mp[x+1][y]=who;}
	}
	if (robot[who].dir=='E') 
	{
		if (y+1>xx)
		{printf("Robot %d crashes into the wall\n",who); done=1;return ;}
		else if (mp[x][y+1])

		{printf("Robot %d crashes into robot %d\n",who,mp[x][1+y]); done=1;return ;}
		else
		{mp[x][y]=0;robot[who].y++;mp[x][y+1]=who;}
	}

}

int main()  
{ 
	int t;
// 	freopen ("F:\\duipai\\1.out","w",stdout);
	cin>>t;  
	while(t--)
	{
		memset(mp,0,sizeof(mp));
		int  n,m;
		int i;
		cin>>xx>>yy;


		cin>>n>>m;
		for (i=1;i<=n;i++)
		{
			scanf("%d %d %c\n",&robot[i].y,&robot[i].x,&robot[i].dir);
 
			mp[robot[i].x][robot[i].y]=i; 
		} 
		char ml;
		int who,times;
		  done=0;
		for (i=1;i<=m;i++)
		{
			scanf("%d %c %d",&who,&ml,×);
			if (done) continue;
 			while(times--)
			{
				if (ml=='L') turnl(who);
				if (ml=='R') turnR(who);
				if (ml=='F') goford(who);
				if (done) break;
			}
		//	printf("----%d--%d--%c\n",robot[1].x,robot[1].y,robot[1].dir);
		}
		if (!done) printf("OK\n");



	 
	}
	
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值