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 ALLACS at 2017-10-12 21:29:25 on Problem 2632
#include <iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=100+5;
typedef pair<int,int>PII;
int m,n;
int a,b;
char left1[]="SENW";
char right1[]="SWNE";
PII robot[maxn];
PII rob;
char first[]="EWNS";
char end1[]="SNEW";
char s[maxn];
int move[maxn];
int time[maxn];
char field[maxn];
bool crash(int x,int k,int t)                       //x为机器人
{
     for(int i=1;i<=a;i++)
        if(i!=x)
          {
              if(robot[i].first==k&&robot[i].second==t) {
                                                                                                                                rob.first=x;
                                                                                                                                rob.second=i;
                                                                                                                                return false;
                                                                               }
          }
    if(k<1||k>m||t<1||t>n) return false;
    return true;
}
bool mine(int k,char c,int t)
{
    if(c=='F') {
                    if(s[k]=='N') {
                                           for(int i=1;i<=t;i++)
                                                {
                                                  robot[k].first--;
                                                  bool pos=crash(k,robot[k].first,robot[k].second);
                                                  if(!pos) return false;
                                                }
                                       }
                    else if(s[k]=='S') {
                                                for(int i=1;i<=t;i++)
                                                    {
                                                      robot[k].first++;
                                                      bool pos=crash(k,robot[k].first,robot[k].second);
                                                      if(!pos) return false;
                                                    }
                                               }
                            else if(s[k]=='W') {
                                                        for(int i=1;i<=t;i++)
                                                           {
                                                          robot[k].second--;
                                                          bool pos=crash(k,robot[k].first,robot[k].second);
                                                          if(!pos) return false;
                                                           }
                                                       }
                                    else if(s[k]=='E') {
                                                                for(int i=1;i<=t;i++)
                                                                    {
                                                                      robot[k].second++;
                                                                      bool pos=crash(k,robot[k].first,robot[k].second);
                                                                      if(!pos) return false;
                                                                     }
                                                               }
              }
    else if(c=='L') {
                           int i;
                           for(i=0;i<4;i++)
                                if(s[k]==left1[i]) break;
                           s[k]=left1[(i+t)%4];
                           }
            else if(c=='R') {
                                    int i;
                                    for(i=0;i<4;i++)
                                        if(s[k]==right1[i]) break;
                                    s[k]=right1[(i+t)%4];
                                   }
        return true;
}
int main()
{
        int t;
        scanf("%d",&t);
        while(t--)
        {
            rob=PII(0,0);
            scanf("%d%d",&m,&n);
            scanf("%d%d",&a,&b);
            int x,y;
            char dir;
            for(int i=0;i<a;i++)
            {
                int j;
                cin>>x>>y>>dir;
                for(j=0;j<4;j++)
                    if(first[j]==dir) break;
                s[i+1]=end1[j];
                robot[i+1].first=x;
                robot[i+1].second=y;
            }
            int c,d;
            char rep;
            for(int i=0;i<b;i++)
            {
                cin>>c>>rep>>d;
                move[i]=c;
                field[i]=rep;
                time[i]=d;
            }
            int i;
            for(i=0;i<b;i++)
            {
                bool z=mine(move[i],field[i],time[i]);
                //bool z=crash(move[i]);
                if(!z) break;
            }
            if(i==b) cout<<"OK"<<endl;
            else if(rob.first==0) printf("Robot %d crashes into the wall\n",move[i]);
                    else printf("Robot %d crashes into robot %d\n",rob.first,rob.second);
        }
       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