POJ2632 Crashing Robots(模拟)
题目链接。
分析:
虽说是简单的模拟,却调试了很长时间。
调试这么长时间总结来的经验:
1.坐标系要和题目建的一样,要不就会有各种麻烦。
2.在向前移动过程中碰到其他的机器人也不行,这个题目说啦:a robot always completes its move before the next one starts moving。
#include <iostream>
#include <cstdio>
#include <cstring> using namespace std; const int maxn = + ; int G[maxn][maxn]; int dx[] = {, , , -};
int dy[] = {, , -, }; struct Robots{
int x, y, d;
}r[+]; int main(){
int A, B, n, m, T, flag, rob, cra_rob;
char s[]; scanf("%d", &T); while(T--) {
flag = ; memset(G, , sizeof(G)); scanf("%d %d", &A, &B);
scanf("%d %d", &n, &m); for(int i=; i<=n; i++) {
scanf("%d %d", &r[i].x, &r[i].y);
scanf("%s", s);
G[r[i].y][r[i].x] = i; switch(s[]) {
case 'N': r[i].d = ; break;
case 'E': r[i].d = ; break;
case 'S': r[i].d = ; break;
case 'W': r[i].d = ; break;
}
} int num, rep;
char act[]; while(m--) {
scanf("%d %s %d", &num, act, &rep);
if(!flag) {
if(act[] == 'L') r[num].d = ((r[num].d - rep)%+)%;
else if(act[] == 'R') r[num].d = (r[num].d + rep) % ;
else {
G[r[num].y][r[num].x] = ;
for(int i=; i<rep; i++) {
r[num].x += dx[r[num].d];
r[num].y += dy[r[num].d]; if(r[num].x <= || r[num].y <= || r[num].x > A || r[num].y > B) {
rob = num;
flag = ;
break;
} else if(G[r[num].y][r[num].x]) {
rob = num;
cra_rob = G[r[num].y][r[num].x];
flag = ;
break;
}
} if(!flag) G[r[num].y][r[num].x] = num;
}
}
} if(flag == ) printf("Robot %d crashes into the wall\n", rob);
else if(flag == ) printf("Robot %d crashes into robot %d\n", rob, cra_rob);
else printf("OK\n");
} return ;
}
POJ2632 Crashing Robots(模拟)的更多相关文章
- POJ-2632 Crashing Robots模拟
题目链接: https://vjudge.net/problem/POJ-2632 题目大意: 在一个a×b的仓库里有n个机器人,编号为1到n.现在给出每一个机器人的坐标和它所面朝的方向,以及m条指令 ...
- poj2632 Crashing Robots
Crashing Robots Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9859 Accepted: 4209 D ...
- POJ2632——Crashing Robots
Crashing Robots DescriptionIn a modernized warehouse, robots are used to fetch the goods. Careful pl ...
- POJ2632 Crashing Robots 解题报告
Description In a modernized warehouse, robots are used to fetch the goods. Careful planning is neede ...
- poj 2632 Crashing Robots 模拟
题目链接: http://poj.org/problem?id=2632 题目描述: 有一个B*A的厂库,分布了n个机器人,机器人编号1~n.我们知道刚开始时全部机器人的位置和朝向,我们可以按顺序操控 ...
- POJ 2632 Crashing Robots (模拟 坐标调整)(fflush导致RE)
题目链接:http://poj.org/problem?id=2632 先话说昨天顺利1Y之后,直到今天下午才再出题 TAT,真是刷题计划深似海,从此AC是路人- - 本来2632是道略微恶心点的模拟 ...
- POJ 2632 Crashing Robots 模拟 难度:0
http://poj.org/problem?id=2632 #include<cstdio> #include <cstring> #include <algorith ...
- 模拟 POJ 2632 Crashing Robots
题目地址:http://poj.org/problem?id=2632 /* 题意:几个机器人按照指示,逐个朝某个(指定)方向的直走,如果走过的路上有机器人则输出谁撞到:如果走出界了,输出谁出界 如果 ...
- Crashing Robots(水题,模拟)
1020: Crashing Robots 时间限制(普通/Java):1000MS/10000MS 内存限制:65536KByte 总提交: 207 测试通过:101 ...
随机推荐
- PreTranslateMessage作用和用法
PreTranslateMessage作用和用法 PreTranslateMessage是消息在送给TranslateMessage函数之前被调用的,绝大多数本窗体的消息都要通过这里,比較经常使用, ...
- HeadFirst设计模式笔记:(六)命令模式 —— 封装调用
1.概念 将来自客户端的请求传入一个对象,从而使你可用不同的请求对客户进行参数化.用于“行为请求者”与“行为实现者”解耦,可实现二者之间的松耦合,以便适应变化.分离变化与不变的因素. 在面向对象的程序 ...
- CentOS 6.4的安装--史上最全-CRPER木木
安装工具及软件: VmwareWorkstation9 CentOS-6.4-x86_64-LiveCD Vmware初始设置: 刚装好的VMWARE启动后,虽说默认已经设置好基础 ...
- 开发Mhealth(即:Mobile Health 移动医疗)应用必知的10个掘金点
近 日,著名移动技术咨询公司Research2Guidance发布了最新版的<移动医疗应用开发者经济>报告.在过去的两年半里,iOS和Android 两大主流移动平台上的移动医疗应用(以下 ...
- buffer cache chain 图
http://orabase.org/index.php/author/djeday84/page/7/
- RHEL7下PXE+Apache+Kickstart无人值守安装操作系统
RHEL7下PXE+Apache+Kickstart无人值守安装操作系统 1.配置yum源 vim /etc/yum.repos.d/development.repo [development] na ...
- python实现登录函数,比较简单
一个简单的python实现登录以及修改密码的函数 #密码错误3次,锁定登录: password_list = ['] def account_login(): Tries = 3 while Trie ...
- BeautifulSoup在Windows下安装(running 2to3)
在windows下安装beautifulsoup经常会出现说是在python3下无法运行Python2的代码,这时需要将Python下的tool下的scripts目录添加到环境变量中,然后运行2to3 ...
- IOS 开发 【objective-c 基础1】
案例:读取本地硬盘上程序根目录下words.txt文件内容,显示每行的字符数. // // main.m // hello // // Created by swack on 15/11/27. // ...
- 自定义鼠标Cursor转变成图片
今天无意做到项目遇到一个好玩的事情,就是当我鼠标移到一个链接上面,并不是像正常那样出现一个小手,而是变成一个小十字架, 下面看图当时第一眼看到总感觉哪里不对,噢噢噢噢 这样的 小手没了,居然是一个图片 ...