做的差点想吐,调来调去,编译器都犯毛病,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. hdu 2896 病毒侵袭_ac自动机

    题意:略 思路:套用ac自动机模板 #include <iostream> #include<cstdio> #include<cstring> using nam ...

  2. Jekins安装

    1. Jekins支持多系统:windows, mac,linux 2. Jekins安装方式有三种:直接war文件安装,安装包安装,将war文件放到web容器安装 3. 在windows下安装 a. ...

  3. Elasticlunr.js 简单介绍

    Elasticlunr.js 项目地址:http://elasticlunr.com/ 代码地址:https://github.com/weixsong/elasticlunr.js 文档地址:htt ...

  4. hdu1106 字符串水题strtok()&&strchr()&&sscanf()+atoi()使用

    字符串的题目 用库函数往往能大大简化代码量 以hdu1106为例 函数介绍 strtok() 原型: char *strtok(char s[], const char *delim); 功能: 分解 ...

  5. ubuntu下ffmpeg的安装,实现支持3gpp等转换

    最近上线的项目,语音格式转码需要调试3gpp,所以需要再spx,3gpp,3gp等格式之间转换,特记录基于ubuntu环境下的环境ffmpeg部署细则 安装测试环境:ubuntu 14.04 64bi ...

  6. UVA 1212 Duopoly

    题目: 两个公司进行投标,竞争一些channels,每个投标可以包含多个channels,且都有一定的收益,每一个channels只能为其中的一个公司利用,同时保证一个公司给出的投标中选中的chann ...

  7. win7系统64位安装oracle10g

    win7系统64位安装oracle10g 下载地址: http://download.oracle.com/otn/nt/oracle10g/10204/10204_vista_w2k8_x64_pr ...

  8. 微信SDK导入报错 Undefined symbols for architecture i386:"operator delete[](void*)", referenced from:

    异常信息: Undefined symbols for architecture i386:  "operator delete[](void*)", referenced fro ...

  9. JSON 日期格式带 T 问题

    var iso = new IsoDateTimeConverter(); iso.DateTimeFormat = "yyyy-MM-dd"; object obj = new  ...

  10. linux修改rm指令执行(数据安全)

    引用文章A:http://hi.baidu.com/jlusuoya/item/32ae398958088755840fabfb 引用介绍:将rm替换为mv. 引用文章B:http://blog.cs ...