POJ 2632 Crashing Robots
来源:互联网 发布:淘宝中国白银原料批发 编辑:程序博客网 时间:2024/04/30 03:01
模拟题
不算特别麻烦,模拟两只小机器人的行为,判断他们是否会撞墙以及相撞
#include <iostream>#include <cstdio>#include <cstring>using namespace std;struct maze{ int x; int y; int dir;};int cdir(char t){ if (t == 'E') return 1; else if (t == 'S') return 2; else if (t == 'W') return 3; return 4;}int main(){ int m[200][200]; maze rob[200]; int T,a,b,n,M,t1,t2,t3,eventrob,i,j,fail; char tc; scanf("%d",&T); while (T--) { scanf("%d%d",&a,&b); scanf("%d%d",&n,&M); memset(m,0,sizeof(m)); for (i=1; i<=n; i++) { scanf("%d%d%*c%c",&t1,&t2,&tc); m[t2][t1]=i; rob[i].x=t2; rob[i].y=t1; rob[i].dir=cdir(tc); //printf("dir=%d\n",rob[i].dir); } fail=0; for (i=0; i<M; i++) { scanf("%d%*c%c%d",&t1,&tc,&t2); if (fail != 0) continue; //printf("->%d %d %d\n",rob[t1].x,rob[t1].y,rob[t1].dir); if (tc == 'F') { switch (rob[t1].dir) { case 1: m[rob[t1].x][rob[t1].y]=0; for (j=0; j<t2 && fail == 0; j++) { rob[t1].y++; // printf("%d %d %d %d\n",rob[t1].x,rob[t1].y,m[rob[t1].x][rob[t1].y],a); if (rob[t1].y > a) fail=-1; if (m[rob[t1].x][rob[t1].y] != 0) fail=m[rob[t1].x][rob[t1].y]; } m[rob[t1].x][rob[t1].y]=t1; break; case 2: m[rob[t1].x][rob[t1].y]=0; for (j=0; j<t2 && fail == 0; j++) { rob[t1].x--; //printf("%d %d %d %d\n",rob[t1].x,rob[t1].y,m[rob[t1].x][rob[t1].y],a); if (rob[t1].x == 0) fail=-1; if (m[rob[t1].x][rob[t1].y] != 0) fail=m[rob[t1].x][rob[t1].y]; } m[rob[t1].x][rob[t1].y]=t1; break; case 3: m[rob[t1].x][rob[t1].y]=0; for (j=0; j<t2 && fail == 0; j++) { rob[t1].y--; //printf("%d %d %d %d\n",rob[t1].x,rob[t1].y,m[rob[t1].x][rob[t1].y],a); if (rob[t1].y == 0) fail=-1; if (m[rob[t1].x][rob[t1].y] != 0) fail=m[rob[t1].x][rob[t1].y]; } m[rob[t1].x][rob[t1].y]=t1; break; case 4: m[rob[t1].x][rob[t1].y]=0; for (j=0; j<t2 && fail == 0; j++) { rob[t1].x++; // printf("%d %d %d %d\n",rob[t1].x,rob[t1].y,m[rob[t1].x][rob[t1].y],a); if (rob[t1].x > b) fail=-1; if (m[rob[t1].x][rob[t1].y] != 0) fail=m[rob[t1].x][rob[t1].y]; } m[rob[t1].x][rob[t1].y]=t1; break; } if (fail != 0) eventrob=t1; } else if (tc == 'L') { t2%=4; for (j=0; j<t2; j++) { rob[t1].dir--; if (rob[t1].dir == 0) rob[t1].dir+=4; } } else if (tc == 'R') { t2%=4; for (j=0; j<t2; j++) { rob[t1].dir++; if (rob[t1].dir == 5) rob[t1].dir-=4; } } //printf("!!%d\n",fail); } if (fail == 0) { printf("OK\n"); } else if (fail == -1) { printf("Robot %d crashes into the wall\n",eventrob); } else { printf("Robot %d crashes into robot %d\n",eventrob,fail); } }}
- 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
- 对象初始化工作要放在appear方法里,不要在initWithNibName里访问view
- STL概述
- POJ 1068 Parencodings
- /etc/profile和/etc/environment的比较
- NGUI研究院之开始学习制作第一个例子(一)
- POJ 2632 Crashing Robots
- VS2008中使用第三方DotNetBar2的ComboBoxEX控件注意细节
- must_add(l_t_s)_(e_t)_(tec_rec)档案
- 蜂鸣器驱动
- [iOS]日历和提醒编程指南(Calendar and Reminders Programming Guide)
- Qt:向QTextEdit中插入图片
- ios UIKit的图形上下文
- Symmetric Tree
- Winform DataGridView 自定义分页