快速切题 poj2632
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 7799 | Accepted: 3388 |
Description
A robot crashes with a wall if it attempts to move outside the area of the warehouse, and two robots crash with each other if they ever try to occupy the same spot.
Input
The second line contains two integers, 1 <= N, M <= 100, denoting the numbers of robots and instructions respectively.
Then follow N lines with two integers, 1 <= Xi <= A, 1 <= Yi <= B and one letter (N, S, E or W), giving the starting position and direction of each robot, in order from 1 through N. No two robots start at the same position.

Figure 1: The starting positions of the robots in the sample warehouse
Finally there are M lines, giving the instructions in sequential order.
An instruction has the following format:
< robot #> < action> < repeat>
Where is one of
- L: turn left 90 degrees,
- R: turn right 90 degrees, or
- F: move forward one meter,
and 1 <= < repeat> <= 100 is the number of times the robot should perform this single move.
Output
- Robot i crashes into the wall, if robot i crashes into a wall. (A robot crashes into a wall if Xi = 0, Xi = A + 1, Yi = 0 or Yi = B + 1.)
- Robot i crashes into robot j, if robots i and j crash, and i is the moving robot.
- OK, if no crashing occurs.
Only the first crash is to be reported.
Sample Input
- 4
- 5 4
- 2 2
- 1 1 E
- 5 4 W
- 1 F 7
- 2 F 7
- 5 4
- 2 4
- 1 1 E
- 5 4 W
- 1 F 3
- 2 F 1
- 1 L 1
- 1 F 3
- 5 4
- 2 2
- 1 1 E
- 5 4 W
- 1 L 96
- 1 F 2
- 5 4
- 2 3
- 1 1 E
- 5 4 W
- 1 F 4
- 1 L 1
- 1 F 20
Sample Output
- Robot 1 crashes into the wall
- Robot 1 crashes into robot 2
- OK
- Robot 1 crashes into robot 2
- 简单的模拟
应用时:15min
实际用时:1h40min
问题:碰撞的先后次序
- #include<cstdio>
- #include <cstring>
- #include <algorithm>
- using namespace std;
- int A,B,n,m;
- int robot[][];
- char rbuff[];
- int dir[];
- const int dx[]={,,,-};
- const int dy[]={,,-,};
- int action[][];
- int tx,ty;
- int ansr;
- bool between(int aim,int gap){
- int sx=robot[gap][];
- int sy=robot[gap][];
- int mingx=min(sx,tx);
- int maxgx=max(sx,tx);
- int mingy=min(sy,ty);
- int maxgy=max(sy,ty);
- int ax=robot[aim][];int ay=robot[aim][];
- if(ax>=mingx&&ax<=maxgx&&ay>=mingy&&ay<=maxgy){
- if(ansr==)ansr=aim;
- else {
- if(abs(robot[ansr][]-sx)>=abs(ax-sx)&&abs(robot[ansr][]-sy)>=abs(ay-sy)){
- ansr=aim;
- }
- }
- return true;
- }
- return false;
- }
- void solve(){
- ansr=;
- for(int i=;i<m;i++){
- int rob=action[i][];
- int rep=action[i][];
- if(action[i][]==){
- robot[rob][]=(robot[rob][]+-rep%)%;
- }
- else if(action[i][]==){
- robot[rob][]=(robot[rob][]+rep%)%;
- }
- else{
- bool fl=false;
- tx=robot[rob][]+rep*dx[robot[rob][]];
- ty=robot[rob][]+rep*dy[robot[rob][]];
- for(int j=;j<=n;j++){
- if(j==rob)continue;
- if(between(j,rob)){
- fl=true;
- }
- }
- if(fl){
- printf("Robot %d crashes into robot %d\n",rob,ansr);return ;
- }
- if(tx<||tx>A||ty<||ty>B){
- printf("Robot %d crashes into the wall\n",rob);return ;
- }
- robot[rob][]=tx;
- robot[rob][]=ty;
- }
- }
- puts("OK");
- }
- int main(){
- #ifndef ONLINE_JUDGE
- freopen("output.txt","w",stdout);
- #endif // ONLINE_JUDGE
- dir['N']=;dir['E']=;dir['S']=;dir['W']=;
- dir['L']=;dir['R']=;dir['F']=;
- int t;
- scanf("%d",&t);
- while(t--){
- scanf("%d%d%d%d",&A,&B,&n,&m);
- for(int i=;i<=n;++i){
- scanf("%d%d%s",robot[i],robot[i]+,rbuff);
- robot[i][]=dir[rbuff[]];
- }
- for(int i=;i<m;i++){
- scanf("%d%s%d",action[i],rbuff,action[i]+);
- action[i][]=dir[rbuff[]];
- }
- solve();
- }
- return ;
- }
快速切题 poj2632的更多相关文章
- 快速切题sgu127. Telephone directory
127. Telephone directory time limit per test: 0.25 sec. memory limit per test: 4096 KB CIA has decid ...
- 快速切题sgu126. Boxes
126. Boxes time limit per test: 0.25 sec. memory limit per test: 4096 KB There are two boxes. There ...
- 快速切题 sgu123. The sum
123. The sum time limit per test: 0.25 sec. memory limit per test: 4096 KB The Fibonacci sequence of ...
- 快速切题 sgu120. Archipelago 计算几何
120. Archipelago time limit per test: 0.25 sec. memory limit per test: 4096 KB Archipelago Ber-Islan ...
- 快速切题 sgu119. Magic Pairs
119. Magic Pairs time limit per test: 0.5 sec. memory limit per test: 4096 KB “Prove that for any in ...
- 快速切题 sgu118. Digital Root 秦九韶公式
118. Digital Root time limit per test: 0.25 sec. memory limit per test: 4096 KB Let f(n) be a sum of ...
- 快速切题 sgu117. Counting 分解质因数
117. Counting time limit per test: 0.25 sec. memory limit per test: 4096 KB Find amount of numbers f ...
- 快速切题 sgu116. Index of super-prime bfs+树思想
116. Index of super-prime time limit per test: 0.25 sec. memory limit per test: 4096 KB Let P1, P2, ...
- 快速切题 sgu115. Calendar 模拟 难度:0
115. Calendar time limit per test: 0.25 sec. memory limit per test: 4096 KB First year of new millen ...
随机推荐
- 如何高效判断java数组是否包含某个值
在java中,我们如何判断一个未排序数组中是否包含一个特定的值?这在java中是一个频繁非常实用的操作.那么什么样的方法才是最高效的方式?当然 ,这个问题在Stack Overflow也是得票率非常高 ...
- nmap参数思维导图
链接:https://pan.baidu.com/s/1vD0A6olQbVNmCCirpHBm0w 提取码:o994
- java中集合格式及json格式的特点和转换
作者原创:转载请注明出处 今天在写代码,遇到一个难点,由于要调用webservice接口,返回的为一个list集合内容,从webservice调用接口返回的为一个string的io流, 在调用接口的地 ...
- c# 、 Asp.net 获取本地IP和MAC地址
using System; using System.Management; using System.Net; public class Program { static void Main(str ...
- MVC 中Simditor上传本地图片
1.引用样式和js文件 <link href="~/Content/scripts/plugins/simditor/css/simditor.css" rel=" ...
- linux中批量替换文本中字符串--转载
(一)通过vi编辑器来替换.vi/vim 中可以使用 :s 命令来替换字符串.:s/well/good/ 替换当前行第一个 well 为 good:s/well/good/g 替换当前行所有 well ...
- c++ 多继承 公有,私有,保护
昨天学习三种继承方式,有些比喻十分形象,特此分享. 首先说明几个术语: 1.基类 基类比起它的继承类是个更加抽象的概念,所描述的范围更大.所以可以看到有些抽象类,他们设计出来就是作为基类所存在的(有些 ...
- stat用法:获取文件对应权限的数字
题目:文件属性为-rw-r--r-- 对应权限为644,如何使用命令获取权限对应的数字?? 举例如下: [linuxidc@localhost ~]$ ll -l-rw-r--r-- 1 linuxi ...
- Python将某文件夹及其子文件夹下某种格式的文件移动到另一个指定的文件下
主要是理解好上面的1~3点的内容,理解三个返回值所代表的意思.如果不清楚的话,可以在代码的for循环的第一句注释输出看看各个代表的是什么 再者就是对 shutil.copy(file_path,new ...
- WebAPI获取客户端请求数据
1.什么是WebAPI,详见:http://www.cxyclub.cn/n/25123/2.一般情况下我们不需要去关心客户端的请求数据,WebAPI会通过自己的方式去将客户端请求的数据转换为实体对象 ...