做的差点想吐,调来调去,编译器都犯毛病,wlgq,幸好1a。

题意:给你机器人怎走的路线,碰撞就输出

#include <cstdlib>
#include <iostream>
#include<cstdio>
#include<cstring>
#define N 110
using namespace std;
struct Rob{
int x,y,dire;//dire 1为e,2为s,3为w,4为n
}rob[N];
int n,m,a,b,map[N][N]; int setdire(char s){
switch(s){
case 'E':return 1;
case 'S':return 2;
case 'W':return 3;
case 'N':return 4;
}
}
void Turn(Rob &rb,char s){
if(s=='R'){
if(rb.dire==4)
rb.dire=1;
else
rb.dire+=1;
}
else{
if(rb.dire==1)
rb.dire=4;
else
rb.dire-=1;
}
}
void init(){
int i,x,y;
char tmp[3];
memset(map,0,sizeof(map));
for(i=1;i<=n;i++)
{
scanf("%d%d%s",&x,&y,tmp);
map[x][y]=i;
rob[i].x=x;
rob[i].y=y;
rob[i].dire=setdire(tmp[0]);
}
}
void solve(){
int i,j,t,num,x,y,tag=1,flag=1;
char tmp;
for(i=0;i<m;i++)
{
scanf("%d %c %d",&t,&tmp,&num);
if(!flag)
continue;
if(tmp!='F')
{
for(j=0;j<num%4;j++)
Turn(rob[t],tmp);
}
else{
x=rob[t].x;
y=rob[t].y;
if(rob[t].dire==1){
for(j=1;j<=num;j++){
x=rob[t].x+j;
if(x>a){
printf("Robot %d crashes into the wall\n",t);
tag=0;
flag=0;
break;
}
if(map[x][y]){
printf("Robot %d crashes into robot %d\n",t,map[x][y]);
tag=0;
flag=0;
break;
}
}
map[rob[t].x][rob[t].y]=0;
map[rob[t].x+num][rob[t].y]=t;
rob[t].x+=num;
}
else if(rob[t].dire==2){
for(j=1;j<=num;j++){
y=rob[t].y-j;
if(y<1){
printf("Robot %d crashes into the wall\n",t);
tag=0;
flag=0;
break;
}
if(map[x][y]){
printf("Robot %d crashes into robot %d\n",t,map[x][y]);
tag=0;
flag=0;
break;
}
}
map[rob[t].x][rob[t].y]=0;
map[rob[t].x][rob[t].y-num]=t;
rob[t].y-=num;
}
else if(rob[t].dire==3){
for(j=1;j<=num;j++){
x=rob[t].x-j;
if(x<1){
printf("Robot %d crashes into the wall\n",t);
tag=0;
flag=0;
break;
}
if(map[x][y]){
printf("Robot %d crashes into robot %d\n",t,map[x][y]);
tag=0;
flag=0;
break;
}
}
map[rob[t].x][rob[t].y]=0;
map[rob[t].x-num][rob[t].y]=t;
rob[t].x-=num;
}
else if(rob[t].dire==4){
for(j=1;j<=num;j++){
y=rob[t].y+j;
if(y>b){
printf("Robot %d crashes into the wall\n",t);
tag=0;
flag=0;
break;
}
if(map[rob[t].x][y]){
printf("Robot %d crashes into robot %d\n",t,map[x][y]);
tag=0;
flag=0;
break;
}
}
map[rob[t].x][rob[t].y]=0;
map[rob[t].x][rob[t].y+num]=t;
rob[t].y+=num;
}
}
} if(tag)
printf("OK\n");
}
int main(int argc, char *argv[])
{
int t,i,j;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&a,&b);
scanf("%d%d",&n,&m);
init();
solve();
}
system("PAUSE");
return EXIT_SUCCESS;
}

poj 2632 Crashing Robots_模拟的更多相关文章

  1. poj 2632 Crashing Robots 模拟

    题目链接: http://poj.org/problem?id=2632 题目描述: 有一个B*A的厂库,分布了n个机器人,机器人编号1~n.我们知道刚开始时全部机器人的位置和朝向,我们可以按顺序操控 ...

  2. POJ 2632 Crashing Robots (模拟 坐标调整)(fflush导致RE)

    题目链接:http://poj.org/problem?id=2632 先话说昨天顺利1Y之后,直到今天下午才再出题 TAT,真是刷题计划深似海,从此AC是路人- - 本来2632是道略微恶心点的模拟 ...

  3. POJ 2632 Crashing Robots 模拟 难度:0

    http://poj.org/problem?id=2632 #include<cstdio> #include <cstring> #include <algorith ...

  4. 模拟 POJ 2632 Crashing Robots

    题目地址:http://poj.org/problem?id=2632 /* 题意:几个机器人按照指示,逐个朝某个(指定)方向的直走,如果走过的路上有机器人则输出谁撞到:如果走出界了,输出谁出界 如果 ...

  5. poj 2632 Crashing Robots(模拟)

    链接:poj 2632 题意:在n*m的房间有num个机器,它们的坐标和方向已知,现给定一些指令及机器k运行的次数, L代表机器方向向左旋转90°,R代表机器方向向右旋转90°,F表示前进,每次前进一 ...

  6. POJ 2632 Crashing Robots(较为繁琐的模拟)

    题目链接:http://poj.org/problem?id=2632 题目大意:题意简单,N个机器人在一个A*B的网格上运动,告诉你机器人的起始位置和对它的具体操作,输出结果: 1.Robot i ...

  7. POJ 2632 Crashing Robots (坑爹的模拟题)

    Crashing Robots Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6599   Accepted: 2854 D ...

  8. poj 2632 Crashing Robots

    点击打开链接 Crashing Robots Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6655   Accepted: ...

  9. Crashing Robots POJ 2632 简单模拟

    Description In a modernized warehouse, robots are used to fetch the goods. Careful planning is neede ...

随机推荐

  1. JSONObject和JSONArray的简单使用(json-lib)

    一. jar包 commons-lang.jar commons-beanutils.jar commons-collections.jar commons-logging.jar ezmorph.j ...

  2. 如何煉成NET架構師

    微软的DotNet 开发绝对是属于那种入门容易提高难的技术.而要能够成为DotNet 架构师没有三年或更长时间的编码积累基本上是不可能的.特别是在大型软件项目中,架构师是项目核心成员,承上启下,因此 ...

  3. Keepalived+Lvs+Mysql主主复制

    一简单介绍 Keepalived+lvs+mysql主主复制是比較经常使用的一种Mysql高可用方案,当中lvs 提供读负载均衡,Keepalived通过虚拟vip漂移实现故障自己主动转移,而Mysq ...

  4. 用Unity做的一个小游戏,仿照一个样例写的,个人认为文章写的不错,哈哈

  5. 具体解释EBS接口开发之物料导入API

    create_item inv_item_grp.create_item(p_commit => fnd_api.g_true, -- p_item_rec => l_item_rec, ...

  6. Tomcat 的三种(bio,nio.apr) 高级 Connector 运行模式

    tomcat的运行模式有3种.修改他们的运行模式.3种模式的运行是否成功,可以看他的启动控制台,或者启动日志.或者登录他们的默认页面http://localhost:8080/查看其中的服务器状态. ...

  7. SqlServer判断数据库、表、存储过程、函数是否存在

    假设场景是: 需要给一个脚本给客户更新, 这个对象可能存在或不存在 -- 更新存储过程 USE [数据库名] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ...

  8. nodejs 计算内存使用率

    //计算内存使用率 function calcMem(){ let mem_total = os.totalmem(), mem_free = os.freemem(), mem_used = mem ...

  9. Mongoose的使用

    最近想做一个练手的App小项目.考虑到数据接口的问题,因为关系型数据库用的比较多,也有一定经验了,所以打算使用比较火的MongoDB作为数据库,下面就介绍一下Mongoose的使用方法吧. 概念:Mo ...

  10. 移动网页版Meta 标签

    viewport 大部分移动浏览器都接受,比如 Opera Mobile, iPhone, Android, Iris, IE, BlackBerry, Obigo, Firefox 最基本的例子,在 ...