1.Link:

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

http://bailian.openjudge.cn/practice/2632/

2.Content:

3.Method:

模拟题,特别注意方位的问题,和平常的方向有区别

另外要注意旋转方向也可以重复多次的

另外提供测试供参考,来自

http://poj.org/showmessage?message_id=130353

4.Code:

 #include <iostream>
#include <cstring> using namespace std; struct Point
{
int x;
int y;
int d;//direction
}; const int idx_x[] = {,,,-};
const int idx_y[] = {,,-,};
const char arr_d[] = {'N','E','S','W'};
const int num_d = ; int main()
{
//freopen("D://input.txt","r",stdin); int i,j; int k;
cin >> k; int flag; while(k--)
{
flag = ; int w,h; //a,b use w,h clearly
cin >> w >> h; int m,n;
cin >> n >> m; Point *arr_point = new Point[n]; int **arr_mark = new int*[h];
for(i = ; i < h; ++i)
{
arr_mark[i] = new int[w];
memset(arr_mark[i], , sizeof(int) * w);
} char ch;
for(i = ; i < n; ++i)
{
cin >> arr_point[i].x >> arr_point[i].y;
cin.get();
cin >> ch; arr_mark[arr_point[i].y - ][arr_point[i].x - ] = i + ; for(j = ; j < num_d; ++j) if(arr_d[j] == ch) break;
arr_point[i].d = j;
} //for(i = 0; i < n; ++i)
//{
// cout << "Point " << i << ":" << endl;
// cout << arr_point[i].x << endl;
// cout << arr_point[i].y << endl;
// cout << arr_point[i].d << endl;
//} //for(int y = 0; y < h; ++y)
//{
// for(int x = 0; x < w; ++x) cout << arr_mark[y][x] << " ";
// cout << endl;
//} for(i = ; i < m; ++i)
{
int robot,repeat;
char action; cin >> robot;
cin.get();
cin >> action >> repeat; //cout << robot << " " << action << " " << repeat << endl; if(flag)
{
switch(action)
{
case 'L':
arr_point[robot - ].d = (arr_point[robot - ].d - repeat + num_d * repeat) % num_d;
break;
case 'R':
arr_point[robot - ].d = (arr_point[robot - ].d + repeat) % num_d;
break;
case 'F':
for(j = ; j < repeat; ++j)
{
arr_mark[arr_point[robot - ].y - ][arr_point[robot - ].x - ] = ;
arr_point[robot - ].y += idx_y[arr_point[robot - ].d];
arr_point[robot - ].x += idx_x[arr_point[robot - ].d]; if((arr_point[robot - ].y - ) < || (arr_point[robot - ].y - ) >= h
|| (arr_point[robot - ].x - ) < || (arr_point[robot - ].x - ) >= w)
{
cout << "Robot " << robot << " crashes into the wall" << endl;
flag = ;
break;
}
else if(arr_mark[arr_point[robot - ].y - ][arr_point[robot - ].x - ])
{
cout << "Robot " << robot << " crashes into robot " << arr_mark[arr_point[robot - ].y - ][arr_point[robot - ].x - ] << endl;
flag = ;
break;
}
}
if(j >= repeat)
{
arr_mark[arr_point[robot - ].y - ][arr_point[robot - ].x - ] = robot;
}
break;
}
} } if(flag)
{
cout << "OK" << endl;
} for(i = ; i < h; ++i) delete [] arr_mark[i];
delete [] arr_mark; delete [] arr_point;
} //fclose(stdin); return ;
}

5.Reference:

05-02 10:07