Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

半小时,,一次AC,,哇哦,,贴代码留恋

Posted by 20133820 at 2014-08-26 10:49:32 on Problem 2632
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

struct Robt{
     int x,y;
     char o;
}robt[105];   //i号robt的位置以及变化来的状态

int A,B,n,m;
char W = 'W', E = 'E', N = 'N', S = 'S';

int main(){
    int T;
    scanf("%d",&T);
    while(T--){
        scanf("%d%d%d%d",&A,&B,&n,&m);
        int flag = 0;      //1表示出界,2表示相撞,0表示OK
        int ansrobt, ansrobt2;
        int g[105][105];
        memset(g, 0, sizeof(g));
        for(int i = 1; i<=n; i++){
            int a,b;
            char c;
            cin>>a>>b>>c;
            robt[i].x = a;
            robt[i].y = b;
            if(c == W) robt[i].o = E;
            else if(c == E) robt[i].o = W;
            if(c == N) robt[i].o = S;
            if(c == S) robt[i].o = N;
            g[a][b] = i;
        }

        for(int j = 0; j<m; j++){
            int num,rep;
            char c;
            cin>>num>>c>>rep;
            if(flag)  continue;

            if(c == 'F'){
                g[robt[num].x][robt[num].y] = 0;
                char ch = robt[num].o;
                for(int k = 0; k<rep; k++){
                    if(ch == W) robt[num].x += 1;
                    if(ch == E) robt[num].x -= 1;
                    if(ch == N) robt[num].y -= 1;
                    if(ch == S) robt[num].y += 1;
                    if(g[robt[num].x][robt[num].y]){
                        ansrobt = num;
                        ansrobt2 = g[robt[num].x][robt[num].y];
                        flag = 2;
                        break;
                    }
                    if(robt[num].x == 0 || robt[num].x == A+1 || robt[num].y == 0 || robt[num].y == B+1){
                        ansrobt = num;
                        flag = 1;
                        break;
                    }
                }
                g[robt[num].x][robt[num].y] = num;
            }
            if(c == 'L'){
                char ch = robt[num].o;
                if(rep%4 == 1){
                    if(ch == W) robt[num].o = S;
                    if(ch == E)  robt[num].o = N;
                    if(ch == N) robt[num].o = W;
                    if(ch == S) robt[num].o = E;
                }
                if(rep%4 == 2){
                    if(ch == W) robt[num].o = E;
                    if(ch == E)  robt[num].o = W;
                    if(ch == N) robt[num].o = S;
                    if(ch == S) robt[num].o = N;
                }
                if(rep%4 == 3){
                    if(ch == W) robt[num].o = N;
                    if(ch == E)  robt[num].o = S;
                    if(ch == N) robt[num].o = E;
                    if(ch == S) robt[num].o = W;
                }
            }
            if(c == 'R'){
                char ch = robt[num].o;
                if(rep%4 == 1){
                    if(ch == W) robt[num].o = N;
                    if(ch == E)  robt[num].o = S;
                    if(ch == N) robt[num].o = E;
                    if(ch == S) robt[num].o = W;
                }
                if(rep%4 == 2){
                    if(ch == W) robt[num].o = E;
                    if(ch == E)  robt[num].o = W;
                    if(ch == N) robt[num].o = S;
                    if(ch == S) robt[num].o = N;
                }
                if(rep%4 == 3){
                    if(ch == W) robt[num].o = S;
                    if(ch == E)  robt[num].o = N;
                    if(ch == N) robt[num].o = W;
                    if(ch == S) robt[num].o = E;
                }
            }
        }

        switch(flag){
             case 0: printf("OK\n");break;
             case 1: printf("Robot %d crashes into the wall\n",ansrobt);break;
             case 2: printf("Robot %d crashes into robot %d\n",ansrobt,ansrobt2);break;
        }
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator