码迷,mamicode.com
首页 > 其他好文 > 详细

Poj 2632

时间:2017-01-19 07:55:22      阅读:219      评论:0      收藏:0      [点我收藏+]

标签:i++   stdio.h   sig   make   bsp   can   sizeof   push   scanf   

这个题做的真是拖沓。是一个模拟题,有很多细节需要注意:
1.要求输出第一个装车的,但是是多组数据。所以要把所有数据读完,如果发现一个装车的就break,就造成下一个数据错误。另一方面,如果发现一个撞车的,就不要继续走了,这个WA的我莫名其妙,结果网上找到了一组数据,发现了这个问题,但是要继续读输入。
2.拖的时间比较长(去逛街了),有一些细节错误。没把方向变换的操作单独放在相应情况下,造成WA。
  1 // #includes {{{
  2     #include<stdio.h>
  3     #include<stdlib.h>
  4     #include<string.h>
  5     #include<math.h>
  6     #include<assert.h>
  7     #include<stdarg.h>
  8     #include<time.h>
  9     #include<limits.h>
 10     #include<ctype.h>
 11     #include<string>
 12     #include<map>
 13     #include<set>
 14     #include<queue>
 15     #include<algorithm>
 16     #include<vector>
 17     #include<iostream>
 18     #include<sstream>
 19     using namespace std;
 20     // }}}
 21     // #defines {{{
 22     #define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
 23     #define SZ(x) ((int)(x).size())
 24     #define ALL(x) (x).begin(),(x).end()
 25     #define REP(i,n) for(int i=0;i<(n);i++)
 26     #define REP1(i,a,b) for(int i=(a);i<=(b);i++)
 27     #define PER(i,n) for(int i=(n)-1;i>=0;i--)
 28     #define PER1(i,a,b) for(int i=(a);i>=(b);i--)
 29     #define RI(x) scanf("%d",&x)
 30     #define DRI(x) int x;RI(x)
 31     #define RII(x,y) scanf("%d%d",&x,&y)
 32     #define DRII(x,y) int x,y;RII(x,y)
 33     #define RIII(x,y,z) scanf("%d%d%d",&x,&y,&z)
 34     #define DRIII(x,y,z) int x,y,z;RIII(x,y,z)
 35     #define RS(x) scanf("%s",x)
 36     #define PI(x) printf("%d\n",x)
 37     #define PIS(x) printf("%d ",x)
 38     #define CASET int ___T,cas=1;scanf("%d",&___T);while(___T--)
 39     #define CASEN0(n) int cas=1;while(scanf("%d",&n)!=EOF&&n)
 40     #define CASEN(n) int cas=1;while(scanf("%d",&n)!=EOF)
 41     #define MP make_pair
 42     #define PB push_back
 43 
 44     #define MS0(x) memset(x,0,sizeof(x))
 45     #define MS1(x) memset(x,-1,sizeof(x))
 46 
 47     #define F first
 48     #define S second
 49     typedef pair<int,int> PII;
 50     typedef long long LL;
 51     typedef unsigned long long ULL;
 52     // }}}
 53 
 54 const int N=550;
 55 int n,m;
 56 int a[N][N];
 57 int b[N][N];
 58 int car[N][2];
 59 int DD[300];
 60 main(){
 61     //freopen("o.txt","w",stdout);
 62     CASET{
 63         DD[E]=0;DD[N]=1;DD[W]=2;DD[S]=3;
 64         int num,que;
 65         cin>>n>>m;
 66         cin>>num>>que;
 67         for(int i=0;i<N;i++)for(int j=0;j<N;j++)a[i][j]=0;
 68         for(int i=1;i<=num;i++){
 69         int x,y;
 70         char d;
 71         cin>>x>>y>>d;
 72         car[i][1]=x;
 73         car[i][2]=y;
 74         a[x][y]=i;
 75         b[x][y]=DD[d];
 76         }
 77         string ans="OK";
 78         int r1=0,r2=0;
 79         for(int i=0;i<que;i++){
 80             int q,re;
 81             char f;
 82             cin>>q>>f>>re;
 83             if (ans=="OK")
 84             if (f==F){
 85                     int dr=b[car[q][1]][car[q][2]];
 86                     for(int ii=0;ii<re;ii++){
 87                         a[car[q][1]][car[q][2]]=0;
 88                         b[car[q][1]][car[q][2]]=0;
 89                         if (dr==0)
 90                         car[q][1]++;
 91                         if (dr==2)
 92                             car[q][1]--;
 93                         if (dr==1)
 94                             car[q][2]++;
 95                         if (dr==3)
 96                             car[q][2]--;
 97                         if (a[car[q][1]][car[q][2]]!=0){
 98                             r1=q;
 99                             r2=a[car[q][1]][car[q][2]];
100                             if (ans=="OK")ans="robot ";
101                             break;
102                         }
103                         if (car[q][1]>n || car[q][2]>m || car[q][1]<1 || car[q][2]<1) {
104                             r1=q;
105                             if (ans=="OK") ans="wall";
106                             break;
107                         }
108                         a[car[q][1]][car[q][2]]=q;
109             //            cout<<car[q][1]<<" "<<car[q][2]<<" "<<q<<endl;
110                     }
111                     b[car[q][1]][car[q][2]]=dr;
112             //        cout<<dr<<" "<<car[q][1]<<" "<<car[q][2]<<"!!!"<<endl;
113 
114             }else{
115             if (f==L){
116                 re%=4;
117             }
118             if (f==R){
119                 re%=4;
120                 re=4-re;
121             }
122             //    cout<<re<<" "<<b[car[q][1]][car[q][2]]<<"!"<<endl;
123                 b[car[q][1]][car[q][2]]+=re;
124                 b[car[q][1]][car[q][2]]%=4;
125             }
126         }
127         if (ans=="OK") cout<<ans<<endl;
128         else{
129             //cout<<ans<<endl;
130             if (r2!=0)
131             cout<<"Robot "<<r1<<" crashes into robot "<<r2<<endl;
132             else cout<<"Robot "<<r1<<" crashes into the wall"<<endl;
133 
134         }
135 
136     }
137 }

 

Poj 2632

标签:i++   stdio.h   sig   make   bsp   can   sizeof   push   scanf   

原文地址:http://www.cnblogs.com/nisige/p/6305328.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!