美文网首页
G - 曙色

G - 曙色

作者: miaozasnone | 来源:发表于2019-07-26 16:13 被阅读0次

http://acm.hnucm.edu.cn/vjudge/contest/view.action?cid=111#problem/G

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.


image

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 one line for each test case:

OUT

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 

AC代码
面向对象一次ac,哈哈

#include<iostream>
#include<cstring>
#define qc std::ios::sync_with_stdio(false)
using namespace std;
const int maxl=1e2+10;
const int mod=1000000;
const string V="NWSE";
int t,X,Y,n1,n2,t1,t2;
bool isbreak=false;
int MAP[101][101];
struct mac
{
    int x,y;
    int v;
    void getv(char c,int *v){
        v[0]=v[1]=0;
        if(c=='W')v[0]=-1;
        if(c=='E')v[0]=1;
        if(c=='S')v[1]=-1;
        if(c=='N')v[1]=1;
    }
    void left(){
        if(v==3)v=0;
        else v++;
    }
    void right(){
        if(v==0)v=3;
        else v--;
    }
    void go(){
        int tv[2],mine=MAP[x][y];
        getv(V[v],tv);
        x+=tv[0];
        y+=tv[1];
        if(MAP[x][y]){
            if(!isbreak)printf("Robot %d crashes into robot %d\n",mine,MAP[x][y]);
            isbreak=true;
        }
        else if(x>X||y>Y||x<1||y<1){
            //printf("%d\n",isbreak);
            if(!isbreak)printf("Robot %d crashes into the wall\n",mine);
            isbreak=true;
        }
        else{
            MAP[x-tv[0]][y-tv[1]]=0;
            MAP[x][y]=mine;
        }
    }
};
mac ma[maxl];
char c;
int main(){
    qc;
    cin>>t;
    while (t--)
    {
        memset(MAP,0,sizeof(MAP));
        memset(ma,0,sizeof(ma));
        isbreak=false;
        cin>>X>>Y>>n1>>n2;
        for(int i=1;i<=n1;i++){
            cin>>ma[i].x>>ma[i].y>>c;
            ma[i].v=V.find(c);
            MAP[ma[i].x][ma[i].y]=i;
        }
        for(int i=1;i<=n2;i++){
            int *v;
            cin>>t1>>c>>t2;
            if(c=='L')while(t2--)ma[t1].left();
            if(c=='R')while(t2--)ma[t1].right();
            if(c=='F')while (t2--)ma[t1].go();
        }
        if(!isbreak)printf("OK\n");
    }
}

相关文章

  • G - 曙色

    http://acm.hnucm.edu.cn/vjudge/contest/view.action?cid=11...

  • 曙色

    毕竟是夜了, 屋外一切静极, 静到要听出静的声音来。 小小的灯火光中, 被考验的。是 闭目枯坐的我。 生字长句的草...

  • 曙色

    我总是被你迷惑 被一朵云,困在 天空的尽头 夜之尽头 当清晨第一缕微光睁开 城市的眼睛 总有一些灵魂 还沉溺在梦中...

  • 曙色

    东方欲晓渐日光,星月隐隐褪光芒 神清气爽风拂面,满坐春风散花香 蓝空朗照烂漫,珍露盈帘斑斓 鸟鸣花涧,虫语草滩 晨...

  • 黎明的曙色

    陈色厚重的记忆 立在久违的月下 新的思念在亲吻黎明 永恒的誓言 远方的脚步 发现归途跳跃的音符 财福的金字塔写满爱意缕缕

  • 曙色•烟花遥

    客坐前堂里,晓色碧园春。 郎行妾舞半,花影弄姿笑。 芣草兼霞浦,残阳恋四方。 手把新欢景,相识复梦中。

  • 曙色流观

    新韵 白沙镜水靓悠悠, 柳映平波暖日流。 迤逦琅峰独自乐, 嫣然曙色动云舟。

  • 曙色中的鸟鸣

    穿过树梢间的婉转 弥漫成繁华 一夜沉寂,次第苏醒…… 【永进简评】首行一个借代紧紧扣题,且意象丰满,颇有感染力,穿...

  • 曙色——水木诗社

    365日历诗6月10日 贾梅士日暨葡侨日 贾梅士吟葡国魂, 华人赤心思澳门。 两制平安乐民业, 一代雄略拓...

  • 曙色从发梢滴落

    曙色从发梢滴落 一丝一缕一丝不苟 开始浇灌夏天的田园 不能告诉你的话 经过下一次月色溶溶 就会长成枝上嫩蕊 还有椭...

网友评论

      本文标题:G - 曙色

      本文链接:https://www.haomeiwen.com/subject/rkddrctx.html