做的差点想吐,调来调去,编译器都犯毛病,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. [ASP.NET] 图形验证码破解-以简单图形为例

    原文 http://www.dotblogs.com.tw/joysdw12/archive/2013/06/08/captcha-cracked.aspx 前言 这次来讲个比较有趣的主题,就是该如何 ...

  2. selenium webdriver使用过程中出现Element is not currently visible and so may not be interacted with的处理方法

    参考文章: http://blog.csdn.net/passionboyxie/article/details/28661107 http://www.spasvo.com/ceshi/open/k ...

  3. Linux系统编程(12)——shell基础

    Shell的作用是解释执行用户的命令,用户输入一条命令,Shell就解释执行一条,这种方式称为交互式(Interactive),Shell还有一种执行命令的方式称为批处理(Batch),用户事先写一个 ...

  4. live555学习之RTSP连接建立以及请求消息处理过程

    1,RTSP连接的建立过程    RTSPServer类用于构建一个RTSP服务器,该类同时在其内部定义了一个RTSPClientSession类,用于处理单独的客户会话.    首先创建RTSP服务 ...

  5. WebStorm JavaScript 开发神器

    WebStorm 百度百科 http://baike.baidu.com/view/5443872.htm?fr=aladdin

  6. hdu1166 树状数组

    不知道为什么用C++输入输出死活不过,换成C的就过了... #include <stdio.h> #include <string.h> //================= ...

  7. java实现写大量数据到文件中

    生成.txt文件 生成.csv文件 生成.xls文件 import java.io.BufferedWriter; import java.io.File; import java.io.FileOu ...

  8. 一笔画问题(floyd+oular+dfs)

    一笔画问题 时间限制:3000 ms  |  内存限制:65535 KB 难度:4   描述 zyc从小就比较喜欢玩一些小游戏,其中就包括画一笔画,他想请你帮他写一个程序,判断一个图是否能够用一笔画下 ...

  9. char与byte的差别

    非常多刚開始学习的人(包含我,已经学了一年多java了)肯会对char和byte这两种数据类型有所疑惑,相互混淆,今天特地查了好多资料,对byte和char两种数据类型进行了总结和比較,先将结果与大家 ...

  10. 力挺8天入门wpf【转载】

    8天入门wpf—— 第八天 最后的补充 摘要: 从这一篇往前看,其实wpf中还有很多东西没有讲到,不过我的原则还是将比较常用的知识点过一遍,如果大家熟悉了这些知识,基本功也就打的差不多了,后续可以等待 ...