poj2632求调
  • 板块题目总版
  • 楼主bbbzzx
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/9/27 20:37
  • 上次更新2024/9/27 22:23:49
查看原帖
poj2632求调
372498
bbbzzx楼主2024/9/27 20:37

样例全过,不知道错在哪。

代码:

#include<iostream>
#include<map>
using namespace std;
int p,q,n,m;
map<char , pair<int,int> > mp;
struct node{
	int x,y,id;
	char ch;
}a[250];
void calc(int i, char op, int cnt)
{
	char c=a[i].ch;
	if(op=='L')
	{
		for(int j=1;j<=(cnt-1)%4+1;j++)
		{
			if(c=='N') a[i].ch='W';
			else if(c=='E') a[i].ch='N';
			else if(c=='S') a[i].ch='E';
			else if(c=='W') a[i].ch='S';
		}	
	}
	else
	if(op=='R')
	{
		for(int j=1;j<=(cnt-1)%4+1;j++)
		{
			if(c=='N') a[i].ch='E';
			else if(c=='E') a[i].ch='S';
			else if(c=='S') a[i].ch='W';
			else if(c=='W') a[i].ch='N';
		}	
	}
}
int judge(int id)
{
	for(int i=1;i<=n;i++)
		if(a[id].x==a[i].x&&a[id].y==a[i].y&&i!=id)
			return i;
	if(a[id].x<1||a[id].x>p||a[id].y<1||a[id].y>q)
		return -1;
	return 0;
}
int main()
{
	mp['N']={0,1};
	mp['E']={1,0};
	mp['S']={0,-1};
	mp['W']={-1,0};
	int T;
	cin>>T;
	while(T--)
	{
		char str[250];
		int num[250],rep[250];
		cin>>p>>q>>n>>m;
		for(int i=1;i<=n;i++)
		{
			char c;
			cin>>a[i].x>>a[i].y>>c;
			a[i].id=i,a[i].ch=c;
		}
		for(int i=1;i<=m;i++)
			cin>>num[i]>>str[i]>>rep[i];
		bool flag=0;
		for(int i=1;i<=m;i++)
		{
			calc(num[i],str[i],rep[i]);
			if(str[i]=='F')
			{
				for(int j=1;j<=rep[i];j++)
				{
					a[num[i]].x+=mp[a[num[i]].ch].first;
					a[num[i]].y+=mp[a[num[i]].ch].second;
					int k=judge(num[i]);
					if(k==-1)
					{
						flag=1;
						cout<<"Robot "<<num[i]<<" crashes into the wall";
						break;
					}
					else
					if(k==0)
						continue;
					else
					{
						flag=1;
						cout<<"Robot "<<num[i]<<" crashes into robot "<<k;
						break;
					}
				}	
			}
			if(flag)
				break;
		}
		if(!flag)
			cout<<"OK";
		cout<<endl;
	}
	return 0;
}
2024/9/27 20:37
加载中...