POJ-2632-Crashing Robots
来源:互联网 发布:天猫双十一数据直播间 编辑:程序博客网 时间:2024/04/30 01:47
模拟~注意X、Y方向以及边界的处理。对于机器人所占的点,开一个数组记录哪个机器人在该点,然后进行判断即可
代码:
#include<cstdio>#include<cstring>#include<iostream>#define MAX 101using namespace std;int c,r,n,m,movex[4]={0,1,0,-1},movey[4]={1,0,-1,0};int exits[MAX][MAX];struct rbot{ int x; int y; int p;}a[MAX];bool isborder(int x,int y){ if(x<=0||x>c||y<=0||y>r)return true; return false;}int GetPos(char op){ switch(op) {case 'N':return 0;case 'E':return 1;case 'S':return 2;case 'W':return 3; }}int main(){ int cas; scanf("%d",&cas); while(cas--) {memset(exits,0,sizeof(exits));memset(a,0,sizeof(a));scanf("%d%d",&c,&r);scanf("%d%d",&n,&m);for(int i=1;i<=n;i++){ char itc[4]; scanf("%d%d%s",&a[i].x,&a[i].y,&itc); a[i].p=GetPos(itc[0]); exits[a[i].y][a[i].x]=i;}int flag=0;for(int i=0;i<m;i++){ int opt,times; char op[5]; scanf("%d%s%d",&opt,&op,×); if(flag)continue; int x=a[opt].x; int y=a[opt].y; int p=a[opt].p; exits[y][x]=0; if(op[0]=='F') {for(int j=0;j<times;j++){ x+=movex[p]; y+=movey[p]; if(isborder(x,y)) {printf("Robot %d crashes into the wall\n",opt);flag=1;break; } if(exits[y][x]) {printf("Robot %d crashes into robot %d\n",opt,exits[y][x]);flag=1;break; }}a[opt].x=x;a[opt].y=y;exits[y][x]=opt; } else if(op[0]=='L') {times%=4;a[opt].p=(a[opt].p-times+4)%4; } else {times%=4;a[opt].p=(a[opt].p+times)%4; }}if(!flag) printf("OK\n"); } return 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
- 事务
- 我系成功举办android实战培训
- 河北金融学院csdn高校俱乐部的精品android讲堂圆满结束
- 一个小小的课程设计 -- 对排序的总结
- 存储过程
- POJ-2632-Crashing Robots
- ADO.NET中COMMAND对象的ExecuteNonQuery、ExcuteReader和ExecuteScalar方法
- Java String对象的经典问题(new String())
- 鼠标移动到热点上,显示详细信息(显示数据库的信息)
- Cloud Foundry中Service Gateway功能以及通信机制
- 游标和触发器
- Ajax
- poj2186 有向图强连通缩点
- 2010年3月编程语言排行榜