第四章例题
自己敲了一遍4-5
1 #include<cstdio> 2 #include<cstring> 3 4 #define maxn 1000 5 6 struct Command 7 { 8 char c[10]; 9 int r1,r2,c1,c2; 10 int a,x[20]; 11 }cmd[maxn]; 12 13 int r,c,n; 14 15 16 int simulate(int *r0,int *c0) 17 { 18 for(int i=0;i<n;i++) 19 { 20 if(cmd[i].c[0]=='E') 21 { 22 //printf("r1=%d r2=%d c1=%d c2=%d\n",cmd[i].r1,cmd[i].r2,cmd[i].c1,cmd[i].c2); 23 if(cmd[i].r1==*r0 && cmd[i].c1==*c0) 24 { 25 *r0=cmd[i].r2; 26 *c0=cmd[i].c2; 27 } 28 else if(cmd[i].r2==*r0 && cmd[i].c2==*c0) 29 { 30 *r0=cmd[i].r1; 31 *c0=cmd[i].c1; 32 } 33 } 34 35 int rm=0,cm=0; 36 37 if(cmd[i].c[0]=='D') 38 { 39 40 if(cmd[i].c[1]=='R') 41 { 42 for(int j=0;j<cmd[i].a;j++) 43 { 44 if(cmd[i].x[j]==*r0) 45 return 0; 46 if(cmd[i].x[j]<*r0) 47 rm--; 48 } 49 } 50 51 if(cmd[i].c[1]=='C') 52 { 53 for(int j=0;j<cmd[i].a;j++) 54 { 55 if(cmd[i].x[j]==*c0) 56 return 0; 57 if(cmd[i].x[j]<*c0) 58 cm--; 59 } 60 } 61 62 } 63 64 if(cmd[i].c[0]=='I') 65 { 66 if(cmd[i].c[1]=='R') 67 { 68 for(int j=0;j<cmd[i].a;j++) 69 { 70 if(cmd[i].x[j]<=*r0) 71 rm++; 72 } 73 } 74 75 if(cmd[i].c[1]=='C') 76 { 77 for(int j=0;j<cmd[i].a;j++) 78 { 79 //printf("*c0=%d cmd[%d].x[%d]=%d\n", *c0,i,j,cmd[i].x[j]); 80 if(cmd[i].x[j]<=*c0) 81 cm++; 82 } 83 } 84 } 85 86 (*r0)+=rm; 87 (*c0)+=cm; 88 } 89 90 return 1; 91 } 92 93 94 int main() 95 { 96 for(;;) 97 { 98 scanf("%d%d%d",&r,&c,&n); 99 100 for(int i=0;i<n;i++) 101 { 102 scanf("%s",cmd[i].c); 103 //printf("%s\n",cmd[i].c); 104 105 if(cmd[i].c[0]=='E') 106 { 107 scanf("%d%d%d%d",&cmd[i].r1,&cmd[i].r2,&cmd[i].c1,&cmd[i].c2); 108 //printf("r1=%d r2=%d c1=%d c2=%d\n",cmd[i].r1,cmd[i].r2,cmd[i].c1,cmd[i].c2); 109 } 110 else 111 { 112 scanf("%d",&cmd[i].a); 113 114 printf("a=%d\n",cmd[i].a); 115 116 for(int j=0;j<cmd[i].a;j++) 117 scanf("%d",&cmd[i].x[j]); 118 119 //for(int j=0;j<cmd[i].a;j++) 120 //printf("%d\n",cmd[i].x[j]); 121 } 122 123 } 124 125 int q; 126 127 scanf("%d",&q); 128 129 while(q--) 130 { 131 int r0,c0; 132 133 scanf("%d%d",&r0,&c0); 134 135 printf("(%d,%d) ",r0,c0); 136 137 if(simulate(&r0,&c0)) 138 printf("move to (%d,%d)\n",r0,c0); 139 else 140 printf("GONE\n"); 141 } 142 } 143 144 return 0; 145 }
Yosoro