POJ 2632 Crashing Robots 模拟题目
来源:互联网 发布:数据港股票最新消息 编辑:程序博客网 时间:2024/04/29 17:35
我做的时候是把地图又给反转回去了 ~~~一定要看好方向吧~~~~~
#include <cstdio>#include <cstring>#include <cstdlib>#include <iostream>#include <algorithm>#include <cmath>using namespace std;int map[1101][1110];struct node{ int x,y; int dir;//0,1,2,3,N,W,S,E}rob[112345];int move[4][2] = {{0,1},{-1,0},{0,-1},{1,0}};int main(){ int t; cin >> t; int a, b; int n, m; char s[5]; int i; while(t--){ memset(map,0,sizeof(map)); scanf("%d %d", &a, &b); scanf("%d %d", &n, &m); for(i = 1;i <= n;i++){ scanf("%d %d %s", &rob[i].x, &rob[i].y, s); map[rob[i].x][rob[i].y] = i; if(s[0] =='N') rob[i].dir = 0; else if(s[0]=='W') rob[i].dir =1; else if(s[0]=='S') rob[i].dir = 2; else if(s[0] == 'E') rob[i].dir = 3; }// for(int i = 1;i <=a;i++){// for(int j = 1;j <= b;j++){// printf("%d ",map[i][j]);// }// printf("\n");// } bool flag = false; int t1, t2; while(m--){ scanf("%d%s%d", &t1,s,&t2); if(flag) continue;//第一次相撞已经记录完了 if(s[0] == 'L'){ rob[t1].dir+=t2; rob[t1].dir%=4; }else if(s[0] == 'R'){ rob[t1].dir-=t2; rob[t1].dir%=4; rob[t1].dir=(rob[t1].dir+4)%4; }else{ int x = rob[t1].x; int y = rob[t1].y; while(t2--){ x = rob[t1].x; y = rob[t1].y; x+=move[rob[t1].dir][0]; y+=move[rob[t1].dir][1];// printf("%d", rob[t1].dir);// printf("x==%d y==%d\n", x, y); if(x <=0||x > a||y<=0||y>b){ printf("Robot %d crashes into the wall\n", t1); flag = true; break; }else if(map[x][y] != 0){ printf("Robot %d crashes into robot %d\n", t1, map[x][y]); flag = true; break; }else { map[x][y] = t1; map[rob[t1].x][rob[t1].y] = 0; rob[t1].x = x; rob[t1].y = y; } } }// for(int i = 1;i <=a;i++){// for(int j = 1;j <= b;j++){// printf("%d ",map[i][j]);// }// printf("\n");// } } if(!flag) printf("OK\n"); } return 0;}
0 0
- POJ 2632 Crashing Robots 模拟题目
- POJ 2632 Crashing Robots 模拟
- POJ 2632 Crashing Robots 模拟
- poj 2632 Crashing Robots, 模拟
- POJ 2632-Crashing Robots(模拟)
- POJ 2632 Crashing Robots 模拟
- POJ 2632 Crashing Robots 模拟的方法
- POJ 2632 Crashing Robots 水模拟
- POJ 2632 Crashing Robots(模拟)
- POJ 2632:Crashing Robots:模拟试手
- POJ-2632--Crashing Robots模拟题
- poj 2632 Crashing Robots(模拟)
- POJ 2632 Crashing Robots(模拟题)
- POJ 2632 Crashing Robots(模拟)
- poj-2632-- Crashing Robots -- 模拟法
- POJ-2632-Crashing Robots-模拟题
- POJ 2632 Crashing Robots(简单模拟)
- poj 2632 Crashing Robots(模拟)
- css中的单位详解
- window 上 sphinx 搜索
- Java之多线程
- spring事物配置
- ThreadLocal在基于Fluent NHibernate框架系统中的应用
- POJ 2632 Crashing Robots 模拟题目
- Activity全流程套路来了 大转盘什么什么的都不是事
- OJ--单向链表反转
- hdu5762(2016多校第三场,思维题)
- Merge讲解与实例
- javaweb学习总结(四)——Http协议
- PLSql -- 练习2 cursor 显式/隐式游标
- Java之异常
- yii2中导入js,css文件