POJ 2632 Crashing Robots 模拟题目

7 篇文章 0 订阅
我做的时候是把地图又给反转回去了 ~~~一定要看好方向吧~~~~~
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;
int map[1101][1110];
struct node
{
    int x,y;
    int dir;//0,1,2,3,N,W,S,E
}rob[112345];

int move[4][2] = {{0,1},{-1,0},{0,-1},{1,0}};

int main()
{
    int t;
    cin >> t;
    int a, b;
    int n, m;
    char s[5];
    int i;
    while(t--){
        memset(map,0,sizeof(map));
        scanf("%d %d", &a, &b);
        scanf("%d %d", &n, &m);
        for(i = 1;i <= n;i++){
            scanf("%d %d %s", &rob[i].x, &rob[i].y, s);
            map[rob[i].x][rob[i].y] = i;
            if(s[0] =='N')  rob[i].dir = 0;
            else if(s[0]=='W') rob[i].dir =1;
            else if(s[0]=='S') rob[i].dir = 2;
            else if(s[0] == 'E') rob[i].dir = 3;
        }
//        for(int i = 1;i <=a;i++){
//            for(int j = 1;j <= b;j++){
//                printf("%d ",map[i][j]);
//            }
//            printf("\n");
//        }
        bool flag = false;
        int t1, t2;
        while(m--){
            scanf("%d%s%d", &t1,s,&t2);
            if(flag) continue;//第一次相撞已经记录完了
            if(s[0] == 'L'){
                rob[t1].dir+=t2;
                rob[t1].dir%=4;
            }else if(s[0] == 'R'){
                rob[t1].dir-=t2;
                rob[t1].dir%=4;
                rob[t1].dir=(rob[t1].dir+4)%4;
            }else{
                int x = rob[t1].x;
                int y = rob[t1].y;
                while(t2--){
                    x = rob[t1].x;
                    y = rob[t1].y;
                    x+=move[rob[t1].dir][0];
                    y+=move[rob[t1].dir][1];
//                    printf("%d", rob[t1].dir);
//                    printf("x==%d y==%d\n", x, y);
                    if(x <=0||x > a||y<=0||y>b){
                        printf("Robot %d crashes into the wall\n", t1);
                        flag = true;
                        break;
                    }else if(map[x][y] != 0){
                        printf("Robot %d crashes into robot %d\n", t1, map[x][y]);
                        flag = true;
                        break;
                    }else {
                        map[x][y] = t1;
                        map[rob[t1].x][rob[t1].y] = 0;
                        rob[t1].x = x;
                        rob[t1].y = y;
                    }
                }
            }
//             for(int i = 1;i <=a;i++){
//            for(int j = 1;j <= b;j++){
//                printf("%d ",map[i][j]);
//            }
//            printf("\n");
//        }
        }
        if(!flag)
            printf("OK\n");
    }

    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值