POJ2632
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<cmath>
using namespace std;
#define INF 0x3f3f3f3f
int dir[5][2] = {{0,0},{0,1},{-1,0},{0,-1},{1,0}};
struct robot{
int x,y;
int face;
}r[105];//1 N ,3 S, 2 W, 4 E
int map[105][105];
int main(){
int t,a,b,n,m;
scanf("%d",&t);
while(t--){
memset(map,0,sizeof(map));
scanf("%d%d",&a,&b);
scanf("%d%d",&n,&m);
char tmp;
for (int i = 1; i <= n; i++)
{
scanf("%d %d %c",&r[i].x,&r[i].y,&tmp);
map[r[i].x][r[i].y] = i;
if(tmp == 'N')r[i].face = 1;
else if(tmp == 'S')r[i].face = 3;
else if(tmp == 'W')r[i].face = 2;
else if(tmp == 'E')r[i].face = 4;
}
int ind,rep,flag = 0;
for (int i = 1; i <= m; i++)
{
scanf("%d %c %d",&ind,&tmp,&rep);
if(flag){continue;}
if(tmp == 'L'){
for (int k = 0; k < rep; k++)
{
if(r[ind].face == 4)r[ind].face = 1;
else r[ind].face ++;
}
}else if(tmp == 'R'){
for (int k = 0; k < rep; k++)
{
if(r[ind].face == 1)r[ind].face = 4;
else r[ind].face --;
}
}
else if(tmp == 'F')
{
map[r[ind].x][r[ind].y] = 0;
for (int k = 0; k < rep; k++)
{
r[ind].x += dir[r[ind].face][0];
r[ind].y += dir[r[ind].face][1];
if(r[ind].x < 1 || r[ind].x > a){flag = 1;break;}
if(r[ind].y < 1 || r[ind].y > b){flag = 1;break;}
if(map[r[ind].x][r[ind].y]!=0){
flag = 2;
printf("Robot %d crashes into robot %d\n",ind,map[r[ind].x][r[ind].y]);
break;
}
}
if(flag == 1)printf("Robot %d crashes into the wall\n",ind);
if(flag == 0)map[r[ind].x][r[ind].y] = ind;
}
}
if(flag == 0)printf("OK\n");
}
return 0;
}
POJ2632的更多相关文章
- 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 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8388 Accepted: 3631 D ...
- POJ2632——Crashing Robots
Crashing Robots DescriptionIn a modernized warehouse, robots are used to fetch the goods. Careful pl ...
- POJ2632 Crashing Robots(模拟)
题目链接. 分析: 虽说是简单的模拟,却调试了很长时间. 调试这么长时间总结来的经验: 1.坐标系要和题目建的一样,要不就会有各种麻烦. 2.在向前移动过程中碰到其他的机器人也不行,这个题目说啦:a ...
- poj2632 【模拟】
In a modernized warehouse, robots are used to fetch the goods. Careful planning is needed to ensure ...
- 快速切题 poj2632
Crashing Robots Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7799 Accepted: 3388 D ...
- POJ2632 Crashing Robots 解题报告
Description In a modernized warehouse, robots are used to fetch the goods. Careful planning is neede ...
- 【POJ2632】Crashing Robots
题目传送门 本题知识点:模拟 模拟机器人的运作过程,分别有三种功能,L 则是左转90°,R 则是右转90°,L 则是前进1格.让我们去模拟并判断它们的状态. 输入: 第一行是测试样例 第二行分别是矩形 ...
随机推荐
- php工作笔记1-数组常用方法总结,二维数组的去重,上传图片到oss服务器
1.二维数组去重,生成二维数组 private function array_unique_fb($array2D){ $data = array(); foreach($array2D as $k ...
- PHP memory_get_usage()管理内存
PHP memory_get_usage()管理内存 我们在实际编码中,要想实现对内存的查看和操作,许多程序员们第一个想到的就是PHP memory_get_usage()这个PHP脚本内存函数. 下 ...
- 3、python,read(),readlines()和readline()
我们谈到"文本处理"时,我们通常是指处理的内容. Python 对文件对象的操作提供了三个"读"方法: .read()..readline() 和 .readl ...
- 在spring框架中配置Quartz定时器发生错误: class org.springframework.scheduling.quartz.JobDetailBean has interface org.quartz.JobDetail as sup
这是由于spring和Quartz的不兼容性造成的.我的spring是4.0.2,但是Quartz是2.2.3的,换了一个1.8版本的Quartz就解决问题了.
- Perl语言
Perl是高级.通用.直译式.动态的程序语言家族.最初设计者拉里·沃尔(Larry Wall)为了让在UNIX上进行报表处理的工作变得更方便,决定开发一个通用的脚本语言,而在1987年12月18日发表 ...
- MySQL 第一篇
一.MySQL介绍 MySQL是一个关系型数据库管理系统,由瑞典MySQL AB公司开发,目前属于Oracle公司.MySQL是一种关联数据库管理系统,关联数据库将数据保存在不同的表中,而不是将所有数 ...
- nagios二次开发(四)---nagios监控原理和nagios架构简介
nagios监控原理 下面根据上面摘自网络的原理图对nagios的监控原理进行一下简单的说明: 1.nagios通过nsca进行被动监控.那么什么是被动监控呢?被动监测:就是指由被监测的服务器主动上传 ...
- unity3d 知识点随记
1.transform.translate是增加transform面板相应的数值x,y,z是以本地坐标系为方向:transform.transformdirection是以世界坐标系为方向,可以去测试 ...
- Reveal的使用及破解方法
Reveal的使用其实真的很简单,就如第一张镇楼图的效果一样.中间是3D可视化当前APP页面的视图,左侧则是这些UI元素和层次结构,而右侧则是View的属性,你可以修改View的颜色.frame等等, ...
- design pattern
1. visitor design pattern http://butunclebob.com/ArticleS.UncleBob.IuseVisitor