码迷,mamicode.com
首页 > 其他好文 > 详细

2020 BIT冬训-模拟与暴力 D - Crashing Robots POJ - 2632

时间:2021-02-05 10:47:53      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:integer   temp   pre   script   支持   ase   star   proc   diameter   

Problem Description
In 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 all robots occupy a circular floor space with a diameter of 1 meter. Assume there are N robots, numbered from 1 through N. You will get to know the position and orientation of each robot, and all the instructions, which are carefully (and mindlessly) followed by the robots. Instructions are processed in the order they come. No two robots move simultaneously; a robot always completes its move before the next one starts moving.
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 first line of input is K, the number of test cases. Each test case starts with one line consisting of two integers, 1 <= A, B <= 100, giving the size of the warehouse in meters. A is the length in the EW-direction, and B in the NS-direction.
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

Output one line for each test case:
  • 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
poj好像不支持c++11。导致我一开始{}初始化的pair用不了(早知道用数组了)。只能后面一步步定义。这题倒是没什么陷阱和细节。模拟就完事了。
#include<cstdio>
#include<algorithm>
using namespace std;
int k,a,b,n,m,i1,i3,flag1,flag2,ans1,ans2;
char temp,i2;
struct robot{
    int x,y,d;
}r[105];
pair<int,int>dir[4];
int main(){
    dir[0].first=0,dir[0].second=1,dir[1].first=1,dir[1].second=0,dir[2].first=0,dir[2].second=-1,dir[3].first=-1,dir[3].second=0;
    scanf("%d",&k);
    while(k--){
        scanf("%d%d%d%d",&a,&b,&n,&m);
        for(int i=0;i<n;i++){
            scanf("%d%d %c",&r[i].x,&r[i].y,&temp);
            if(temp==N)
                r[i].d=0;
            else if(temp==E)
                r[i].d=1;
            else if(temp==S)
                r[i].d=2;
            else if(temp==W)
                r[i].d=3;
        }
        flag1=0;
        flag2=0; 
        for(int i=0;i<m;i++){
            scanf("%d %c%d",&i1,&i2,&i3);
            i1--;
            if(flag1||flag2)
                continue;
            if(i2==L)
                r[i1].d=(r[i1].d-i3%4+4)%4;
            else if(i2==R)
                r[i1].d=(r[i1].d+i3%4)%4;
            else    
                for(int i=0;i<i3;i++){
                    r[i1].x+=dir[r[i1].d].first;
                    r[i1].y+=dir[r[i1].d].second;
                    if(r[i1].x==0||r[i1].x==a+1||r[i1].y==0||r[i1].y==b+1){
                        flag1=1;
                        ans1=i1;
                    }
                    if(flag1)
                        break;;
                    for(int i=0;i<n;i++){
                        if(i1!=i&&r[i1].x==r[i].x&&r[i1].y==r[i].y){
                            flag2=1;
                            ans1=i1;
                            ans2=i;
                            break;
                        }
                    }
                    if(flag2)
                        break;
                }
        }
        if(flag2)
            printf("Robot %d crashes into robot %d\n",ans1+1,ans2+1);
        else if(flag1)
            printf("Robot %d crashes into the wall\n",ans1+1);
        else
            printf("OK\n");
    }
}

 

 

 

2020 BIT冬训-模拟与暴力 D - Crashing Robots POJ - 2632

标签:integer   temp   pre   script   支持   ase   star   proc   diameter   

原文地址:https://www.cnblogs.com/mikku39/p/14375126.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!