做的差点想吐,调来调去,编译器都犯毛病,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. ajax jquery return没有返回值

    错误写法: function editdivisionmember(division_id,users_id){ $.ajax({ type:"POST", url:"/ ...

  2. 多个ORACLE HOME的情况,默认的ORACLE HOME是哪个,以及如何更改HOME

    如果系统里安装了多个ORACLE产品,那么在注册表里,有可能也会有多个ORACLE HOME,在不设置系统环境变量的情况下,默认情况使用哪个ORACLE HOME? HKEY_LOCAL_MACHIN ...

  3. Liferay门户网站portal

    转自:http://www.oschina.net/p/liferay+portal Liferay 是一个完整的门户解决方案,基于J2EE的应用,使用了EJB以及JMS等技术,前台界面部分使用Str ...

  4. UESTC_王之迷宫 2015 UESTC Training for Search Algorithm & String<Problem A>

    A - 王之迷宫 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit  ...

  5. UESTC_Little Deer and Blue Cat CDOJ 1025

    In DOTA, there are two Intellegence heroes. One is Enchantress, who is usually called Little Deer by ...

  6. (转)Java 的swing.GroupLayout布局管理器的使用方法和实例

    摘自http://www.cnblogs.com/lionden/archive/2012/12/11/grouplayout.html (转)Java 的swing.GroupLayout布局管理器 ...

  7. python中的那些“神器”

    "武林至尊,宝刀屠龙,号令天下,莫敢不从,倚天不出,谁与争锋",这是神器.不过今天要说的python中的"神器"就没有这么厉害了,这里要说的"神器&q ...

  8. Hard Process(二分)

    Hard Process Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submi ...

  9. 擅长排列的小明 II(找规律)

    擅长排列的小明 II 时间限制:1000 ms  |  内存限制:65535 KB 难度:3 描述 小明十分聪明,而且十分擅长排列计算. 有一天小明心血来潮想考考你,他给了你一个正整数n,序列1,2, ...

  10. 9年经验,总结SEO职业瓶颈

    昨天与某集团的副总与部门总监沟通了一些关于SEO发展与瓶颈的问题,有很多感触,今天整理出来分享给大家.其实关于SEO瓶颈这个话题已经不是一年两年了,很多新人老人越来越困惑,9年历程一路风雨走来,希望能 ...