MyPojId == zhaozhouyang
模拟题,注意方向数字化,转向时对4取模就好了。
还有想知道一下向这种题目的输入 数字 数字 字母 的形式有什么简便的方法吗?
由于中间有空格,我把字母当做字符串处理了。
#include<iostream>
#include<string>
using namespace std;
struct robot
{
int we, ns,
ori;//ori : 0 N 1 E 2 S 3 W
}ro[101];
string str;
int move[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
int ori[200], vst[101][101];
int main()
{
int k;
ori['N'] =
0, ori['E'] = 1, ori['S'] = 2, ori['W'] = 3;
ori['L'] =
3, ori['R'] = 1;
scanf("%d",
&k);
while(k--)
{
int a, b, n, m, id, repet, act, temp;
memset(vst, 0, sizeof(vst));
scanf("%d%d%d%d", &a, &b,
&n, &m);
for(int i = 1; i <= n; i )
{
cin >> ro[i].we
>> ro[i].ns
>> str;
ro[i].ori = ori[str[0]];
vst[ro[i].we][ro[i].ns] = i;
}
int state = 0, ans1, ans2;
while(m--)
{
cin >> id
>> str
>> repet;
if (str[0] != 'F')
{
repet %= 4;
ro[id].ori = (ro[id].ori repet * ori[str[0]]) % 4;
}
else
{
while(!state && repet--)
{