| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
请大家帮帮忙In Reply To:请有时间的话看看,错在什么地方了? Posted by:tcxgsy at 2005-10-07 21:29:50 > #include"stdio.h"
> #include"iostream.h"
>
> struct mad1
> {int x;
> int y;
> char z;
> int p;
> };
> struct mad2
> { int x;
> char z;
> int y;
> };
> int K,A,B,N,M;
> struct mad1 a[1000];
> struct mad2 b[1000];
> int number,w;
> int th()
> { int i;
> for(i=0;i<M;i++)
> if(a[number].x==a[i].x&&a[number].y==a[i].y)
> if(i!=number) return (i+1);
> return 0;
> }
> int ac()
> { int i,j;
> for(i=0;i<N;i++)
> { number=b[i].x-1;
> if(b[i].z!='F')
> { if(b[i].z=='S')
> { a[number].p+=b[i].y%4;
> if(a[number].p>4) a[number].p-=4;
> }
> else {a[number].p-=b[i].y%4;
> if(a[number].p<=0) a[number].p+=4;
> }
> }
> else
> { if(a[number].p==1)
>
> for(j=1;j<=b[i].y;j++)
> { a[number].x++;
> if(a[number].x>A)
> { printf("Robot %d crashes into the wall\n",number+1);return 0;}
> w=th();
> if(w!=0)
> {printf("Robot %d crashes into robot %d\n",number+1,w);return 1;}
> }
>
> if(a[number].p==3)
>
> for(j=1;j<=b[i].y;j++)
> { a[number].x--;
> if(a[number].x<0)
> {printf("Robot %d crashes into the wall\n",number+1);return 0;}
> w=th();
> if(w!=0)
> {printf("Robot %d crashes into robot %d\n",number+1,w);return 1;}
> }
>
> if(a[number].p==4)
>
> for(j=1;j<=b[i].y;j++)
> { a[number].y++;
> if(a[number].y>B)
> {printf("Robot %d crashes into the wall\n",number+1);return 0;}
> w=th();
> if(w!=0)
> {printf("Robot %d crashes into robot %d\n",number+1,w);return 1;}
> }
> if(a[number].p==2)
>
> for(j=1;j<=b[i].y;j++)
> { a[number].y--;
> if(a[number].y<0)
> {printf("Robot %d crashes into the wall\n",number+1);return 0;}
> w=th();
> if(w!=0)
> {printf("Robot %d crashes into robot %d\n",number+1,w);return 1;}
> }
> }
> }
> printf("OK\n");
> return 1;
> }
> int main()
>
> { int i;
>
> scanf("%d",&K);
> while(K)
> { cin>>A>>B>>M>>N;
> for(i=0;i<M;i++)
> { cin>>a[i].x>>a[i].y>>a[i].z;
> if(a[i].z=='E') a[i].p=1;
> if(a[i].z=='W') a[i].p=3;
> if(a[i].z=='N') a[i].p=4;
> if(a[i].z=='S') a[i].p=2;
> }
> for(i=0;i<N;i++)
> cin>>b[i].x>>b[i].z>>b[i].y;
>
> ac();
> K--;
> }
> return 1;
> }
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator