UVa 118 Mutant Flatworld Explorers (模拟机器人移动)
2014-01-12 08:02
429 查看
118 - Mutant Flatworld Explorers
Time limit: 3.000 secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=54
旋转时+1或+3再取模即可。
完整代码:
/*0.019s*/ #include<cstdio> #include<cstring> const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}, dr[4] = {'N', 'E', 'S', 'W'}; int main() { bool lostpos[51][51] = {0}; int x, y, w, h, len, dir, i; bool ok; char s[101], c; scanf("%d%d", &w, &h); while (~scanf("%d%d %c\n", &x, &y, &c)) { ok = true; switch (c)// 初始化机器人方向 { case 'N': dir = 0; break; case 'E': dir = 1; break; case 'S': dir = 2; break; case 'W': dir = 3; break; } gets(s); len = strlen(s); for (i = 0; i < len && ok; ++i) { switch (s[i]) { case 'R'://右转 dir = (dir + 1) % 4; break; case 'L'://左转 dir = (dir + 3) % 4; break; case 'F'://向前走 if ((x + dx[dir] > w) || (y + dy[dir] > h) || (x + dx[dir] < 0) || (y + dy[dir] < 0)) { if (!lostpos[x][y])//出界 { printf("%d %d %c LOST\n", x, y, dr[dir]); ok = false, lostpos[x][y] = true; } } else x += dx[dir], y += dy[dir]; break; } } if (ok) printf("%d %d %c\n", x, y, dr[dir]); } return 0; }
相关文章推荐
- Uva-118-Mutant Flatworld Explorers
- UVa 118|Mutant Flatworld Explorers|
- UVa 118 - Mutant Flatworld Explorers
- UVa Problem 118 - Mutant Flatworld Explorers
- Mutant Flatworld Explorers
- [ACM_模拟] UVA 12503 Robot Instructions [指令控制坐标轴上机器人移动 水]
- 紫书章六例题五 移动盒子 UVA 12657 (数组模拟双向链表)
- 紫书章六例题五 移动盒子 UVA 12657 (数组模拟双向链表)
- 紫书章六例题五 移动盒子 UVA 12657 (数组模拟双向链表)
- 紫书章六例题五 移动盒子 UVA 12657 (数组模拟双向链表)
- 例题6-5 移动盒子 UVa 12657 链表(模拟链表)
- [ACM_模拟] UVA 10881 Piotr's Ants[蚂蚁移动 数组映射 排序技巧]
- 例题6-1 并行程序模拟(Concurrency Simulator, ACM/ICPC World Finals 1991, UVa210)
- 紫书章六例题五 移动盒子 UVA 12657 (数组模拟双向链表)
- 紫书章六例题五 移动盒子 UVA 12657 (数组模拟双向链表)
- 紫书章六例题五 移动盒子 UVA 12657 (数组模拟双向链表)
- 紫书章六例题五 移动盒子 UVA 12657 (数组模拟双向链表)
- UVa 133 - The Dole Queue【模拟】
- JS实现窗口加载时模拟鼠标移动的方法
- 模拟,滚动数组,递归(不公平竞赛,uva 1609)