Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
60行左右,大模拟越来越顺手了,加油#define ll long long #define vec vector<int> #define P pair<char,int> #define inf 0x3f3f3f3f #define MAX 105 int T, M, N, A, B, x, y, d, a[MAX][MAX], sign = 1;//a[i][j]:这个位置当前是哪个机器人 int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };//顺时针:上右下左 struct rob { int x, y, k, id;//位置,方向,编号 rob(int a = 0, int b = 0, int c = 0, int s = 0) { x = a, y = b, k = c, id = s; } }; vector<rob> v; void move(int id, char op, int step) { rob & t = v[id]; if (op == 'L') { for (int i = 0; i < step; i++)//向左转 t.k = (t.k - 1 + 4) % 4; } else if (op == 'R') for (int i = 0; i < step; i++)//向右转 t.k = (t.k + 1) % 4; else { a[t.x][t.y] = 0;//从当前位置走开 for (int i = 0; i < step; i++) { t.x += dx[t.k], t.y += dy[t.k]; if (t.x<1 || t.x>A || t.y<1 || t.y>B) { if (sign) printf("Robot %d crashes into the wall\n", t.id), sign = 0; return; } if (a[t.x][t.y] > 0) { if (sign) printf("Robot %d crashes into robot %d\n", t.id, a[t.x][t.y]), sign = 0; return; } } a[t.x][t.y] = t.id; } } int main() { cin >> T; map<char, int> m; m['N'] = 0, m['S'] = 2, m['E'] = 1, m['W'] = 3; while (T--) { memset(a, 0, sizeof(a)); cin >> B >> A >> N >> M; char s; v.clear(); v.push_back(rob()); for (int i = 1; i <= N; i++) { scanf("%d %d %c", &y, &x, &s); a[x][y] = i; v.push_back(rob(x, y, m[s], i)); } int id, step; sign = 1; for (int i = 0; i < M; i++) { scanf("%d %c %d", &id, &s, &step); move(id, s, step); } if (sign) printf("OK\n"); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator