poj2632(Crashing Robots)

题目大意:

一个仓库有N个机器人在移动,仓库的大小为A,B。会有M次操作,(E,W,S,N)分别代表东西南北,机器人在仓库里会有三种情况:1.正在移动的机器人i撞墙。2.正在移动的机器人i遇见机器人j。3.所有机器人没发生任何意外(OK)。根据操作,输出可能的结果。

数据分析

4 //代表几组测试案例

5 4 //代表仓库的大小

2 2  //代表有两个机器人进行两次操作

   1 1 E
 //代表第一个机器人的位置和方向

   5 4 W
//代表第二个机器人的位置和方向

   1 F 7  
//代表编号为1的机器人向前走7次

 
 2 L 7  //代表编号为2的机器人向左转7次。
(R向右转)

解题思路:

模拟即可,模拟机器人操作的每一步,在模拟的过程中判断机器人是否撞墙或者相遇,如果出现此状况就记录下来然后BREAK。最后输出结果。

注意(模拟可能代码会很长,一定要细心,多做几组测试数据调试检验代码的正确性)。

代码:

  1 #include <algorithm>
2 #include <iostream>
3 #include <sstream>
4 #include <cstdlib>
5 #include <cstring>
6 #include <cstdio>
7 #include <string>
8 #include <bitset>
9 #include <vector>
10 #include <queue>
11 #include <stack>
12 #include <cmath>
13 #include <list>
14 #include <map>
15 #include <set>
16 using namespace std;
17 /***************************************/
18 #define ll long long
19 #define int64 __int64
20 /***************************************/
21 const int INF = 0x7f7f7f7f;
22 const double eps = 1e-8;
23 const double PIE=acos(-1.0);
24 const int dx[]= {0,-1,0,1};
25 const int dy[]= {1,0,-1,0};
26 const int fx[]= {-1,-1,-1,0,0,1,1,1};
27 const int fy[]= {-1,0,1,-1,1,-1,0,1};
28 /***************************************/
29 void openfile()
30 {
31 freopen("data.in","rb",stdin);
32 freopen("data.out","wb",stdout);
33 }
34 /**********************华丽丽的分割线,以上为模板部分*****************/
35 char fang[4]= {‘E‘,‘N‘,‘W‘,‘S‘};
36 struct Node
37 {
38 int x,y;
39 int c;
40 } node[200];
41 int main()
42 {
43 int cas;
44 scanf("%d",&cas);
45 while(cas--)
46 {
47 int A,B;
48 int i,j;
49 scanf("%d%d",&A,&B);
50 int n,m;
51 char c1;
52 scanf("%d%d",&n,&m);
53 for(i=1; i<=n; i++)
54 {
55 scanf("%d%d",&node[i].y,&node[i].x);
56 getchar();
57 scanf("%c",&c1);
58 getchar();
59 if (c1==‘E‘)
60 node[i].c=0;
61 if (c1==‘N‘)
62 node[i].c=1;
63 if (c1==‘W‘)
64 node[i].c=2;
65 if (c1==‘S‘)
66 node[i].c=3;
67 }
68 int ce=0;
69 int robot1,robot2,robot3;
70 for(i=1; i<=m; i++)
71 {
72 int robot,sum;
73 char action;
74 scanf("%d",&robot);
75 getchar();
76 scanf("%c",&action);
77 getchar();
78 scanf("%d",&sum);
79 if (ce)
80 continue;
81 if (action==‘L‘)
82 {
83 for(j=0; j<sum; j++)
84 {
85 node[robot].c+=1;
86 if (node[robot].c==4)
87 node[robot].c=0;
88 }
89 }
90 if (action==‘R‘)
91 {
92 for(j=0; j<sum; j++)
93 {
94 node[robot].c-=1;
95 if (node[robot].c==-1)
96 node[robot].c=3;
97 }
98 }
99 if (action==‘F‘)
100 {
101 if (node[robot].c==0)
102 {
103 for(j=1; j<=sum; j++)
104 {
105 if (ce)
106 break;
107 node[robot].y+=1;
108 if (node[robot].y>A)
109 {
110 ce=1;
111 robot1=robot;
112 // printf("Robot %d crashes into the wall\n",robot);
113 }
114 for(int k=1; k<=n; k++)
115 {
116 if (k==robot)
117 continue;
118 if (node[k].x==node[robot].x&&node[k].y==node[robot].y)
119 {
120 ce=2;
121 robot2=robot;
122 robot3=k;
123 // printf("Robot %d crashes into robot %d\n",robot,k);
124 }
125 }
126
127 }
128 }
129 if (node[robot].c==1)
130 {
131 for(j=1; j<=sum; j++)
132 {
133 if (ce)
134 break;
135 node[robot].x+=1;
136 if (node[robot].x>B)
137 {
138 ce=1;
139 robot1=robot;
140 // printf("Robot %d crashes into the wall\n",robot);
141 }
142 for(int k=1; k<=n; k++)
143 {
144 if (k==robot)
145 continue;
146 if (node[k].x==node[robot].x&&node[k].y==node[robot].y)
147 {
148 ce=2;
149 robot2=robot;
150 robot3=k;
151 // printf("Robot %d crashes into robot %d\n",robot,k);
152 }
153 }
154
155 }
156 }
157 if (node[robot].c==2)
158 {
159 for(j=1; j<=sum; j++)
160 {
161 if (ce)
162 break;
163 node[robot].y-=1;
164 if (node[robot].y<1)
165 {
166 ce=1;
167 robot1=robot;
168 // printf("Robot %d crashes into the wall\n",robot);
169 }
170 for(int k=1; k<=n; k++)
171 {
172 if (k==robot)
173 continue;
174 if (node[k].x==node[robot].x&&node[k].y==node[robot].y)
175 {
176 ce=2;
177 robot2=robot;
178 robot3=k;
179 // printf("Robot %d crashes into robot %d\n",robot,k);
180 }
181 }
182
183 }
184 }
185 if (node[robot].c==3)
186 {
187 for(j=1; j<=sum; j++)
188 {
189 if (ce)
190 break;
191 node[robot].x-=1;
192 if (node[robot].x<1)
193 {
194 ce=1;
195 robot1=robot;
196 // printf("Robot %d crashes into the wall\n",robot);
197 }
198 for(int k=1; k<=n; k++)
199 {
200 if (k==robot)
201 continue;
202 if (node[k].x==node[robot].x&&node[k].y==node[robot].y)
203 {
204 ce=2;
205 robot2=robot;
206 robot3=k;
207 // printf("Robot %d crashes into robot %d\n",robot,k);
208 }
209 }
210
211 }
212 }
213 }
214 }
215 if (!ce)
216 printf("OK\n");
217 else if (ce==1)
218 printf("Robot %d crashes into the wall\n",robot1);
219 else if (ce==2)
220 printf("Robot %d crashes into robot %d\n",robot2,robot3);
221 }
222 return 0;
223 }

 
  

时间: 2024-08-05 13:11:43

poj2632(Crashing Robots)的相关文章

POJ 2632 Crashing Robots(模拟题)

Crashing Robots Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7880   Accepted: 3429 Description In a modernized warehouse, robots are used to fetch the goods. Careful planning is needed to ensure that the robots reach their destination

POJ 2632 Crashing Robots (模拟 坐标调整)(fflush导致RE)

题目链接:http://poj.org/problem?id=2632 先话说昨天顺利1Y之后,直到今天下午才再出题 TAT,真是刷题计划深似海,从此AC是路人- - 本来2632是道稍微恶心点的模拟,但毕竟是模拟,一般模拟都是只要示例过了基本就AC了,但这个题很特殊 我开始的时候一直跑不出测试示例,才发现题目中的插图和我构想的坐标系是不一样的(看来还不能轻易忽视掉插图啊) 这个题给出的坐标系是纵轴为y,横轴为x,y从下到上依次递增,x轴是从左到右递增 而我用的二维数组记录的地图,也就是说我的纵

Crashing Robots(imitate)

Crashing Robots Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8124   Accepted: 3528 Description In a modernized warehouse, robots are used to fetch the goods. Careful planning is needed to ensure that the robots reach their destination

POJ2632——Crashing Robots

Crashing Robots DescriptionIn a modernized warehouse, robots are used to fetch the goods. Careful planning is needed to ensure that the robots reach their destinations without crashing into each other. Of course, all warehouses are rectangular, and a

ZOJ 1654 - Place the Robots (二分图最大匹配)

题意:在一个m*n的地图上,有空地,草和墙,其中空地和草能穿透攻击光线,而墙不能.每个机器人能够上下左右攻击,问在地图上最多能放多少个不互相攻击的机器人. 这个题和HDU 1045 -  Fire Net很像.很容易联想到对每个点编号然后互相攻击的点连边再求图的最大独立集,但是这个题数据量太多,超时. 换个思路. 将每个机器人可以攻击到的区域在横和竖方向上分开,这样当横和竖攻击方向都确定时就可以确定一个机器人的放置位置,而在同一个横或竖的攻击区域内不可以再放置机器人. 这样我们把原图上的空地按照

The Preliminary Contest for ICPC Asia Nanjing 2019 D. Robots(概率dp)

题目链接:https://nanti.jisuanke.com/t/41301 题目大意: 给定一个没有循环的有向图,它从节点1开始,到节点n结束. 有一个机器人从1开始,每天都会以相同的概率前往相邻节点之一或静止不动.每天机器人的耐久性消耗量等于经过的天数. 请计算机器人到达节点n时的预期耐久性消耗量. 保证只有一个节点(节点1)的in-degree等于00,并且只有一个节点(节点n)的out-degree等于0.并且图中没有多个边缘. 解题思路: 设dp[i]为从i到达终点n的期望时间那么很

转载:hdu 题目分类 (侵删)

转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012.1013.1014.1017.1019.1021.1028.1029. 1032.1037.1040.1048.1056.1058.1061.1070.1076.1089.1090.1091.1092.1093. 1094.1095.1096.1097.1098.1106.1108.1157.116

CodeIgniter框架中关于URL(index.php)的那些事

最近,在做自己的个人网站时,采用了轻量级的php框架CodeIgniter.乍一看上去,代码清晰简洁,MVC模型非常容易维护.开发时我采用的工具是Netbeans IDE 8.0,当然,本文的内容和开发工具是没有关系的,和我们最后网站采用的服务器有很大的关系.目前最为常用的两款免费web服务器是Apache和Nginx(这两款服务器的比较,可以参考一篇网上的经典文章:http://zyan.cc/nginx_php_v6/).在我网站开发与上线的过程中,刚好两个服务器都用到了,他们配置CodeI

分享CodeIgniter框架中关于URL(index.php)的那些事

A8U论坛最近,在做自己的个人网站时,采用了轻量级的php框架CodeIgniter.乍一看上去,代码清晰简洁,MVC模型非常容易维护.开发时我采用的工具是Netbeans IDE 8.0,当然,本文的内容和开发工具是没有关系的,和我们最后网站采用的服务器有很大的关系.目前最为常用的两款免费web服务器是Apache和Nginx(这两款服务器的比较,可以参考一篇网上的经典文章:http://zyan.cc/nginx_php_v6/).在我网站开发与上线的过程中,刚好两个服务器都用到了,他们配置