poj2632Crashing Robots

http://poj.org/problem?id=2632

好繁琐的一道模拟题 对着测试数据改了将近三个小时才过

View Code
  1 #include<stdio.h>

  2 #include<string.h>

  3 int main()

  4 {

  5     int i,j,t,n,m,a,b,c[101],f[101][101],x[101],y[101],xi,yi,cs1,cs2,crash;

  6     char ci,c1;

  7     scanf("%d",&t);

  8     while(t--)

  9     {

 10         scanf("%d%d",&m,&n);

 11         memset(f,0,sizeof(f));

 12         scanf("%d%d",&a,&b);

 13         int f1 =0 ,f2 = 0;

 14         for(i = 1 ; i <= a ; i++)

 15         {

 16             scanf("%d%d %c", &y[i],&x[i],&c1);

 17             if(y[i]<1||y[i]>m||x[i]<1||x[i]>n)

 18             {

 19                 f1 = 1;

 20                 crash = i;

 21             }

 22             f[x[i]][y[i]] = i;

 23             if(c1=='N')

 24                 c[i]=1;

 25             if(c1=='W')

 26                 c[i]=2;

 27             if(c1=='S')

 28                 c[i] = 3;

 29             if(c1=='E')

 30                 c[i] = 4;

 31         }

 32         for(i = 1; i <= b ; i++)

 33         {

 34             scanf("%d %c %d", &xi,&ci,&yi);

 35             if(ci == 'L')

 36             {

 37                 if(c[xi]+yi%4>4)

 38                 c[xi] = (c[xi]+(yi%4))%4;

 39                 else

 40                     c[xi] = c[xi]+yi%4;

 41             }

 42             else

 43                 if(ci=='R')

 44                 {

 45                     if((4+c[xi]-(yi%4))%4!=0)

 46                     c[xi] = (4+c[xi]-(yi%4))%4;

 47                     else

 48                     c[xi] = 4;

 49                 }

 50             else

 51             if(!f1&&!f2)

 52             for(j = 1; j <= yi ; j++)

 53             {

 54                 if(c[xi] == 3)

 55                     if(x[xi]-1<1)

 56                     {

 57                         crash = xi;

 58                         f1 = 1;

 59                         break;

 60                     }

 61                     else

 62                     {

 63                         x[xi] = x[xi]-1;

 64                         if(f[x[xi]][y[xi]])

 65                         {

 66                             cs1 = xi;

 67                             cs2 = f[x[xi]][y[xi]];

 68                             f2 = 1;

 69                             break;

 70                         }

 71                         else

 72                         {

 73                             f[x[xi]][y[xi]] = xi;

 74                             f[x[xi]+1][y[xi]] = 0;

 75                         }

 76                     }

 77                 if(c[xi] == 2)

 78                     if(y[xi]-1<1)

 79                     {

 80                         crash = xi;

 81                         f1 = 1;

 82                         break;

 83                     }

 84                     else

 85                     {

 86                         y[xi] -= 1;

 87                         if(f[x[xi]][y[xi]])

 88                         {

 89                             cs1 = xi;

 90                             cs2 = f[x[xi]][y[xi]];

 91                             f2 = 1;

 92                             break;

 93                         }

 94                         else

 95                         {

 96                             f[x[xi]][y[xi]] = xi;

 97                             f[x[xi]][y[xi]+1] = 0;

 98                         }

 99                     }

100                 if(c[xi]==1)

101                     if(x[xi]+1>n)

102                     {

103                         crash = xi;

104                         f1 = 1;

105                         break;

106                     }

107                     else

108                     {

109                         x[xi]+=1;

110                         if(f[x[xi]][y[xi]])

111                         {

112                             cs1 = xi;

113                             cs2 = f[x[xi]][y[xi]];

114                             f2 = 1;

115                             break;

116                         }

117                         else

118                         {

119                             f[x[xi]][y[xi]] = xi;

120                             f[x[xi]-1][y[xi]] = 0;

121                         }

122                     }

123                 if(c[xi]==4)

124                     if(y[xi]+1>m)

125                     {

126                         crash = xi;

127                         f1 = 1;

128                         break;

129                     }

130                     else

131                     {

132                         y[xi]+=1;

133                         if(f[x[xi]][y[xi]])

134                         {

135                             cs1 = xi;

136                             cs2 = f[x[xi]][y[xi]];

137                             f2 = 1;

138                             break;

139                         }

140                         else

141                         {

142                             f[x[xi]][y[xi]] = xi;

143                             f[x[xi]][y[xi]-1] = 0;

144                         }

145                     }

146             }

147             //printf("[%d%d][%d][%d%d]\n",f1,f2,c[xi],x[xi],y[xi]);

148         }

149         if(f1)

150             printf("Robot %d crashes into the wall\n",crash);

151         else

152         if(f2)

153             printf("Robot %d crashes into robot %d\n",cs1,cs2);

154         else

155             printf("OK\n");

156     }

157     return 0;

158 }

 

你可能感兴趣的:(Crash)