poj2632Crashing Robots

模拟题,代码长的有点小过分,总算改出来了。。。该死的机器人们

#include<iostream>
#include<cstdio>
using namespace std;

int k,a,b,n,m;
int num,times;
int robots[200][3];
char c;
bool flag,warehouse[200][200];

int main(){
    scanf("%d",&k);
    while(k--){
        flag=true;
        scanf("%d%d",&a,&b);



        for(int i=0;i<=a;i++)
            for(int j=0;j<=b;j++)
            warehouse[i][j]=false;//初始化真的做过了,不要找了大哥!!!!


        scanf("%d%d",&n,&m);
        for(int i=0;i<n;i++){
            scanf("%d%d",&robots[i][0],&robots[i][1]);
            warehouse[robots[i][0]][robots[i][1]]=true;
            getchar();
            scanf("%c",&c);
            if(c=='N') robots[i][2]=0;
            else if(c=='E') robots[i][2]=1;
            else if(c=='S') robots[i][2]=2;
            else if(c=='W') robots[i][2]=3;
        }

        for(int i=0;i<m;i++){
            scanf("%d",&num);
            num--;
            getchar();
            scanf("%c",&c);
            scanf("%d",×);
if(flag){
            if(c=='L'){
                //cout<<c<<"          "<<robots[num][2]<<endl;
                robots[num][2]=(robots[num][2]+3*times)%4;
                //cout<<robots[num][2]<<endl;
            }
            else if(c=='R'){
                //for(int j=0;j<times;j++)
                robots[num][2]=(robots[num][2]+times)%4;
            }
            else if(c=='F'){
                if(robots[num][2]==0){
                    for(int j=1;flag&&j<=times;j++)
                    if(warehouse[robots[num][0]][robots[num][1]+j]||robots[num][1]+j>b){
                        if(robots[num][1]+j>b) printf("Robot %d crashes into the wall\n",num+1);
                        else{
                            for(int k=0;k<n;k++)
                            if(robots[k][0]==robots[num][0]&&robots[k][1]==robots[num][1]+j)
                                printf("Robot %d crashes into robot %d\n",num+1,k+1);
                        }
                        flag=false;
                        break;
                    }
                    warehouse[robots[num][0]][robots[num][1]]=false;
                    warehouse[robots[num][0]][robots[num][1]+times]=true;
                    robots[num][1]+=times;
                }
                if(robots[num][2]==1){
                    for(int j=1;flag&&j<=times;j++)
                    if(warehouse[robots[num][0]+j][robots[num][1]]||robots[num][0]+j>a){
                        if(robots[num][0]+j>a) printf("Robot %d crashes into the wall\n",num+1);
                        else{
                            for(int k=0;k<n;k++)
                            if(robots[k][0]==robots[num][0]+j&&robots[k][1]==robots[num][1])
                                printf("Robot %d crashes into robot %d\n",num+1,k+1);
                        }
                        flag=false;
                        break;
                    }
                    warehouse[robots[num][0]][robots[num][1]]=false;
                    warehouse[robots[num][0]+times][robots[num][1]]=true;
                    robots[num][0]+=times;
                }
                if(robots[num][2]==2){
                    for(int j=1;flag&&j<=times;j++)
                    if(robots[num][1]-j>0){
                    if(warehouse[robots[num][0]][robots[num][1]-j]){
                        //if(robots[num][1]+j>=b) printf("Robot %d crashes into the wall\n",num);
                        //else{
                            for(int k=0;k<n;k++)
                            if(robots[k][0]==robots[num][0]&&robots[k][1]==robots[num][1]-j)
                                printf("Robot %d crashes into robot %d\n",num+1,k+1);
                        //}
                        flag=false;
                        break;
                    }

                    }
                    else{
                        printf("Robot %d crashes into the wall\n",num+1);
                        flag=false;
                        break;
                    }

                    warehouse[robots[num][0]][robots[num][1]]=false;
                    if(flag) warehouse[robots[num][0]][robots[num][1]-times]=true;
                    robots[num][1]-=times;
                }
                if(robots[num][2]==3){
                    for(int j=1;flag&&j<=times;j++)
                    if(robots[num][0]-j>0){
                    if(warehouse[robots[num][0]-j][robots[num][1]]){
                        //if(robots[num][1]+j>=b) printf("Robot %d crashes into the wall\n",num);
                        //else{
                            for(int k=0;k<n;k++)
                            if(robots[k][0]==robots[num][0]-j&&robots[k][1]==robots[num][1])
                                printf("Robot %d crashes into robot %d\n",num+1,k+1);
                        //}
                        flag=false;
                        break;
                    }

                    }
                    else{
                        printf("Robot %d crashes into the wall\n",num+1);
                        flag=false;
                        break;
                    }

                    warehouse[robots[num][0]][robots[num][1]]=false;
                    if(flag) warehouse[robots[num][0]-times][robots[num][1]]=true;
                    robots[num][0]-=times;
                }
            }
        }

            /*for(int j=0;j<n;j++){
                cout<<robots[j][0]<<"   "<<robots[j][1]<<"    "<<robots[j][2]<<endl;
            }*/
}
        if(flag) printf("OK\n");
    }
    return 0;
}



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值