| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 7505 | Accepted: 3279 |
Description
Input
Output
Sample Input
4 5 4 2 2 1 1 E 5 4 W 1 F 7 2 F 7 5 4 2 4 1 1 E 5 4 W 1 F 3 2 F 1 1 L 1 1 F 3 5 4 2 2 1 1 E 5 4 W 1 L 96 1 F 2 5 4 2 3 1 1 E 5 4 W 1 F 4 1 L 1 1 F 20
Sample Output
Robot 1 crashes into the wall Robot 1 crashes into robot 2 OK Robot 1 crashes into robot 2
我讨厌模拟题!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
AC代码如下:
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
struct H
{
int h,z;
char f;
}rt[105];
int t;
int n,m,g,s;
int x[105],y[105];
int map[105][105];
char f[105][105];
char d[105][2];
char b;
int a,c;
int bj;
void DS()//转向
{
c=c%4;
if(b=='R')//左右是对称的
c=4-c;
if(c==1)
{
if(rt[a].f=='N')
rt[a].f='W';
else if(rt[a].f=='E')
rt[a].f='N';
else if(rt[a].f=='S')
rt[a].f='E';
else if(rt[a].f=='W')
rt[a].f='S';
}
else if(c==2)
{
if(rt[a].f=='N')
rt[a].f='S';
else if(rt[a].f=='E')
rt[a].f='W';
else if(rt[a].f=='S')
rt[a].f='N';
else if(rt[a].f=='W')
rt[a].f='E';
}
else if(c==3)
{
if(rt[a].f=='N')
rt[a].f='E';
else if(rt[a].f=='E')
rt[a].f='S';
else if(rt[a].f=='S')
rt[a].f='W';
else if(rt[a].f=='W')
rt[a].f='N';
}
}
void DF()//前进函数
{
int i;
if(rt[a].f=='W')
{
int xx=rt[a].z-c;
for(i=rt[a].z-1;i>=xx;i--)
if(map[rt[a].h][i]!=0&&i>=1)
{printf("Robot %d crashes into robot %d\n",a,map[rt[a].h][i]);bj=1;break;}
if(xx<1&&bj==0)
{printf("Robot %d crashes into the wall\n",a);bj=1;}
if(bj==0)
{map[rt[a].h][rt[a].z]=0;map[rt[a].h][xx]=a;rt[a].z=xx;}
}
else if(rt[a].f=='N')
{
int xx=rt[a].h+c;
for(i=rt[a].h+1;i<=xx;i++)
if(map[i][rt[a].z]!=0&&i<=n)
{printf("Robot %d crashes into robot %d\n",a,map[i][rt[a].z]);bj=1;break;}
if(xx>n&&bj==0)
{printf("Robot %d crashes into the wall\n",a);bj=1;}
if(bj==0)
{map[rt[a].h][rt[a].z]=0;map[xx][rt[a].z]=a;rt[a].h=xx;}
}
else if(rt[a].f=='E')
{
int xx=rt[a].z+c;
for(i=rt[a].z+1;i<=xx;i++)
if(map[rt[a].h][i]!=0&&i<=m)
{printf("Robot %d crashes into robot %d\n",a,map[rt[a].h][i]);bj=1;break;}
if(xx>m&&bj==0)
{printf("Robot %d crashes into the wall\n",a);bj=1;}
if(bj==0)
{map[rt[a].h][rt[a].z]=0;map[rt[a].h][xx]=a;rt[a].z=xx;}
}
else if(rt[a].f=='S')
{
int xx=rt[a].h-c;
for(i=rt[a].h-1;i>=xx;i--)
if(map[i][rt[a].z]!=0&&i>=1)
{printf("Robot %d crashes into robot %d\n",a,map[i][rt[a].z]);bj=1;break;}
if(xx<1&&bj==0)
{printf("Robot %d crashes into the wall\n",a);bj=1;}
if(bj==0)
{map[rt[a].h][rt[a].z]=0;map[xx][rt[a].z]=a;rt[a].h=xx;}
}
}
int main()
{
int i,j;
cin>>t;
while(t--)
{
bj=0;
memset(map,0,sizeof map);
memset(f,0,sizeof f);
cin>>m>>n>>g>>s;
for(i=1;i<=g;i++)
{
cin>>y[i]>>x[i]>>d[i][0];
map[x[i]][y[i]]=i;
rt[i].h=x[i];rt[i].z=y[i];
rt[i].f=d[i][0];
f[x[i]][y[i]]=d[i][0];
//cout<<map[x[i]][y[i]]<<f[x[i]][y[i]]<<endl;
}
for(i=1;i<=s;i++)
{
cin>>a>>b>>c;
if(bj==1)
continue;
if(b=='L')
DS();
else if(b=='R')
DS();
else if(b=='F')
DF();
//cout<<a<<" "<<rt[a].h<<" "<<rt[a].z<<" "<<rt[a].f<<endl<<endl;
}
if(bj==0)
cout<<"OK"<<endl;
}
return 0;
}
POJ 2632 Crashing Robots,布布扣,bubuko.com
原文地址:http://blog.csdn.net/hanhai768/article/details/37503063