Crashing Robots

题意

  • 模拟多个机器人在四个方向的移动,检测crash robot, crash wall, OK这些状态
  • 这是个模拟题需要注意几点:
    • 理解转变方向后移动多少米,和转动方向多少次的区别,这里后一种,在于自己审题
    • crash robot 需要区别哪一个是最先找到的

代码(自己写的比较乱)

int move[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
//1..A or B
std::map<char,int> mp={{'E',0},{'N',1},{'W',2},{'S',3}};
struct node{
int x,y;
int dir;
};//record position
int xb,yb;//x,y边界
node pos[105];//记录当前robot 位置
int ros,ins;//robots num and instruction nums
bool cr(int x1,int x2,int x){
return (x1<=x&&x<=x2)||(x2<=x&&x<=x1);
}
bool crash_robot(node b,node e,node r){
if(cr(b.x,e.x,r.x)&&cr(b.y,e.y,r.y)) return true;
else return false;
}
int check(int a, char ins,int len){
//return 1 crash robot 2 crash wall 3 OK temparily
//
node tmp=pos[a];
if(ins=='L'){
pos[a].dir=(pos[a].dir+len)%4;
}
else if(ins=='R'){
pos[a].dir=(pos[a].dir-len+400)%4;
}
//
else if(ins=='F'){
tmp.x=pos[a].x+move[pos[a].dir][0]*len;
tmp.y=pos[a].y+move[pos[a].dir][1]*len;
tmp.dir=pos[a].dir;
int near_rob=-1;
for(int j=1;j<=ros;j++){
//需要判断谁先撞上 if(j!=a){
if(crash_robot(pos[a],tmp,pos[j])){
if(near_rob==-1) near_rob=j;
else {
if(abs(pos[j].x-pos[a].x+pos[j].y-pos[a].y)<abs(pos[near_rob].x+pos[near_rob].y-pos[a].x-pos[a].y)) near_rob=j;
}
//printf("Robot %d crashes into robot %d\n",a,j); }
}
}
pos[a]=tmp;
if(near_rob!=-1){
printf("Robot %d crashes into robot %d\n",a,near_rob);
return 1;
}
//no crash robot
//check crash wall
if(tmp.x<=0||tmp.x>=xb+1||tmp.y<=0||tmp.y>=yb+1){
printf("Robot %d crashes into the wall\n",a);
pos[a]=tmp;
return 2;
}
pos[a]=tmp;
} return 0;
}

HDU 2300 Crashing Robots的更多相关文章

  1. poj2632 Crashing Robots

    Crashing Robots Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9859   Accepted: 4209 D ...

  2. Crashing Robots(imitate)

    Crashing Robots Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8124   Accepted: 3528 D ...

  3. 模拟 POJ 2632 Crashing Robots

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

  4. Crashing Robots 分类: POJ 2015-06-29 11:44 10人阅读 评论(0) 收藏

    Crashing Robots Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8340   Accepted: 3607 D ...

  5. poj 2632 Crashing Robots

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

  6. Poj OpenJudge 百练 2632 Crashing Robots

    1.Link: http://poj.org/problem?id=2632 http://bailian.openjudge.cn/practice/2632/ 2.Content: Crashin ...

  7. POJ2632——Crashing Robots

    Crashing Robots DescriptionIn a modernized warehouse, robots are used to fetch the goods. Careful pl ...

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

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

  9. Crashing Robots(水题,模拟)

    1020: Crashing Robots 时间限制(普通/Java):1000MS/10000MS     内存限制:65536KByte 总提交: 207            测试通过:101 ...

随机推荐

  1. C++基础 (10) 第十天 C++中类型转换 异常 栈解旋 io操作

    1之前内容的回顾 C语言中的类型转换(int)a  强转可读性太差了 C++把()拆分成了四种转换方式 static_cast static_cast在编译器编译阶段就进行转换了 2.dynamic_ ...

  2. C语言基础 (10) 变量作用域,生命周期 内存结构

    01 课程回顾 1.指针数组 注意: 对于数组来说,在使用sizeof的时候a和&a[0]是不一样的, 虽然以%x打印出来他们都是地址 2.值传递 int a; fun(a); int *** ...

  3. PostgreSQL 安装配置 (亲测可用)

    转自:http://blog.csdn.net/jesseyoung/article/details/41348835 受作者博客限制,请访问上面的链接 ---------- 下面是另一个转载 --- ...

  4. webpack学习笔记(4)--webpack.config.js

    devtool参数 这个参数控制是否生成,以及如何生成source map,已经在官网的doc说明总结了. 下表总结了各个参数和使用的情况 devtool 构建速度 重新构建速度 生产环境 品质(qu ...

  5. js区分ie不同版本

    方法1  js中 if(window.ActiveXObject)//判断浏览器是否属于IE { var browser=navigator.appName var b_version=navigat ...

  6. rabbitMQ学习笔记(一)Windows 与Linux下rabbitMQ的安装

    版权声明:本文为博主原创文章,未经博主允许不得转载. Normal 0 7.8 磅 0 2 false false false EN-US ZH-CN X-NONE /* Style Definiti ...

  7. 【HDOJ 2063】过山车

    [HDOJ 2063]过山车 二分图最大匹配模板题 1女对n男 问匹配最大对数 代码例如以下: #include <iostream> #include <cstdlib> # ...

  8. HDU 4352

    #include <iostream> #include <cstdio> #include <cmath> #include <string.h> # ...

  9. Linux Kernel(Android) 加密算法总结(一)(cipher、compress、digest)

    1. Linux内核支持哪些加密算法 ? 内核支持的加密算法非常多,包含: 对称加密算法.如AES,3DES. 对称password体制的发展趋势将以分组password为重点. 分组password ...

  10. 0x15 KMP

    这个算法本身就不难. poj1961 #include<cstdio> #include<iostream> #include<cstring> #include& ...