做的差点想吐,调来调去,编译器都犯毛病,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. 转:Dynamic Binding Of RDLC To ReportViewer

    Introduction I was struggling to find the solution to bind rdlc dynamically to reportviewer .We had ...

  2. JavaScript 输入验证器工具

    前注:在数据添加的时候很多地方都会涉及到数据的合法性验证,所以有必要提炼成为一个工具.今天偶然间点错网页,弹出一个游戏界面,本来是想看怎么实现的背景音乐的加载的,结果看到一个注册页面的验证JS,所以这 ...

  3. 关于xhEditor

    关于xhEditor xhEditor是一个基于jQuery开发的简单迷你并且高效的在线可视化HTML编辑器,基于网络访问并且兼容IE 6.0+,Firefox 3.0+,Opera 9.6+,Chr ...

  4. Strurts(四)——从Struts原型模拟看大道至简(含实例下载)

    首先,需要再次声明的是:struts是web层的框架.在介绍struts的第一篇文章就已经有了论述,如果不使用struts框架同样可以进行开发,但是需要在Servlet里面写大量的“if……else… ...

  5. 【转】android camera(四):camera 驱动 GT2005

    关键词:android  camera CMM 模组 camera参数  GT2005 摄像头常见问题 平台信息: 内核:linux系统:android 平台:S5PV310(samsung exyn ...

  6. poj 1986 Distance Queries(LCA)

    Description Farmer John's cows refused to run in his marathon since he chose a path much too long fo ...

  7. 跟我一起学extjs5(18--模块的新增、改动、删除操作)

    跟我一起学extjs5(18--模块的新增.改动.删除操作)         上节在Grid展示时做了一个金额单位能够手工选择的功能,假设你要增加其它功能.也仅仅要依照这个模式来操作即可了,比方说你想 ...

  8. JAX-RS开发 hello world

    1.建立maven webapp工程aty-rest. 2. 在pom文件增加spring框架.jax-rs接口.CXF实现 <dependency> <groupId>jav ...

  9. Excel中将时间格式转化成时间戳格式

    时间戳转成正常日期的公式:C1=(A1+8*3600)/86400+70*365+19其中A1表示当时的1249488000时间戳数值其中C1就是所需的日期格式,C1单元格属性改成日期格式就可以了.正 ...

  10. eclipse安装svn插件,在输入url后,一直卡在in progress界面不懂。

    今天遇到上面的情况.网上找了半天都没有找到解决的办法.后来,仔细比对了一下我的eclipse版本和svn版本.发现svn版本真的太老了.用上新的svn后,立马就可以用了 svn - http://su ...