Crashing Robots

题意

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

代码(自己写的比较乱)

  1. int move[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
  2. //1..A or B
  3. std::map<char,int> mp={{'E',0},{'N',1},{'W',2},{'S',3}};
  4. struct node{
  5. int x,y;
  6. int dir;
  7. };//record position
  8. int xb,yb;//x,y边界
  9. node pos[105];//记录当前robot 位置
  10. int ros,ins;//robots num and instruction nums
  11. bool cr(int x1,int x2,int x){
  12. return (x1<=x&&x<=x2)||(x2<=x&&x<=x1);
  13. }
  14. bool crash_robot(node b,node e,node r){
  15. if(cr(b.x,e.x,r.x)&&cr(b.y,e.y,r.y)) return true;
  16. else return false;
  17. }
  18. int check(int a, char ins,int len){
  19. //return 1 crash robot 2 crash wall 3 OK temparily
  20. //
  21. node tmp=pos[a];
  22. if(ins=='L'){
  23. pos[a].dir=(pos[a].dir+len)%4;
  24. }
  25. else if(ins=='R'){
  26. pos[a].dir=(pos[a].dir-len+400)%4;
  27. }
  28. //
  29. else if(ins=='F'){
  30. tmp.x=pos[a].x+move[pos[a].dir][0]*len;
  31. tmp.y=pos[a].y+move[pos[a].dir][1]*len;
  32. tmp.dir=pos[a].dir;
  33. int near_rob=-1;
  34. for(int j=1;j<=ros;j++){
  35. //需要判断谁先撞上
  36. if(j!=a){
  37. if(crash_robot(pos[a],tmp,pos[j])){
  38. if(near_rob==-1) near_rob=j;
  39. else {
  40. 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;
  41. }
  42. //printf("Robot %d crashes into robot %d\n",a,j);
  43. }
  44. }
  45. }
  46. pos[a]=tmp;
  47. if(near_rob!=-1){
  48. printf("Robot %d crashes into robot %d\n",a,near_rob);
  49. return 1;
  50. }
  51. //no crash robot
  52. //check crash wall
  53. if(tmp.x<=0||tmp.x>=xb+1||tmp.y<=0||tmp.y>=yb+1){
  54. printf("Robot %d crashes into the wall\n",a);
  55. pos[a]=tmp;
  56. return 2;
  57. }
  58. pos[a]=tmp;
  59. }
  60. return 0;
  61. }

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. 路飞学城Python-Day59(第五模块记录)

    HTML部分 <!DOCTYPE html> <html lang="en"> <head> <!--head标签的主要作用:文档的头部主 ...

  2. .net 导入Excel

    今天我在做导入Excel的时候遇到了一些问题,顺便说句其实我很少做这方面的!我的需求是导入EXCEL 验证数据正确性 并把数据显示到页面 如有错误信息则弹出来 那具体问题是什么呢? 导入Excel有2 ...

  3. 计蒜客 阿里天池的新任务—简单( KMP水 )

    链接:传送门 思路:KMP模板题,直接生成 S 串,然后匹配一下 P 串在 S 串出现的次数,注意处理嵌套的情况即可,嵌套的情况即 S = "aaaaaa" ,P = " ...

  4. web前端知识框架

  5. Django 中Admin站点的配置

    Admin站点是django提供的一个后台管理页面,可以用来对用户与数据库表数据进行管理. Admin站点配置流程 1.在settings.py文件中INSTALL_APPS列表中添加django.c ...

  6. Context - React跨组件访问数据的利器

    Context提供了一种跨组件访问数据的方法.它无需在组件树间逐层传递属性,也可以方便的访问其他组件的数据 在经典的React应用中,数据是父组件通过props向子组件传递的.但是在某些特定场合,有些 ...

  7. 【codeforces 807B】T-Shirt Hunt

    [题目链接]:http://codeforces.com/contest/807/problem/B [题意] 你在另外一场已经结束的比赛中有一个排名p; 然后你现在在进行另外一场比赛 然后你当前有一 ...

  8. TensorFlow CNN 测试CIFAR-10数据集

    本系列文章由 @yhl_leo 出品,转载请注明出处. 文章链接: http://blog.csdn.net/yhl_leo/article/details/50738311 1 CIFAR-10 数 ...

  9. js js键盘各键对应的代码 ---转

    0x1 鼠标左键\r 0x2 鼠标右键\r 0x3 CANCEL 键\r 0x4 鼠标中键\r 0x8 BACKSPACE 键\r 0x9 TAB 键\r 0xC CLEAR 键\r 0xD ENTE ...

  10. ExtJs之Ext.XTemplate:模板成员函数

    <!DOCTYPE html> <html> <head> <title>ExtJs</title> <meta http-equiv ...