Simulation of POJ-2632 crashing robots

Source: Internet
Author: User

This is a pure simulated question. You only need to simulate it carefully. At the beginning, you changed the row-column relationship according to your own ideas, and the results were in disorder. After this certificate, the AC.

CodeAs follows:

# Include <cstring> # Include <Cstdio> # Include <Cstdlib> # Define Maxn 105 Using   Namespace  STD;  Int  A, B, n, m, X [maxn], Y [maxn], d [maxn];  Int  G [maxn] [maxn];  Int Dir [4 ] [ 2 ] = {- 1 , 0 , 0 , 1 , 1 , 0 , 0 ,- 1  };  Char Box [maxn]; //  Accept information  Struct Message {  Int  No, times;  Char OP [ 3  ];} M;  Bool Update ( Int & Who, Int & Kind ){  If (M. Op [ 0 ] = '  L  ' ){//  Left turn D [M. No] = (d [M. No]-M. Times + 120 ) % 4  ;}  Else   If (M. Op [ 0 ] = '  R  ' ){ //  Right D [M. No] = (d [M. No] + M. Times) % 4 ;}  Else { //  Forward          While (M. times -- ) {G [x [M. No] [Y [M. No] = 0  ;  Int Xx = (X [M. No] + = dir [d [M. No] [ 0  ]);  Int YY = (Y [M. No] + = dir [d [M. No] [ 1  ]); If (Xx < 1 | XX> A | YY < 1 | YY> B) {kind = 1  ;  Return   True  ;}  Else   If (G [XX] [YY]! = 0  ) {Kind = 2 ; WHO = G [XX] [YY];  Return   True  ;}  Else  {G [XX] [YY] = M. No ;}}}  Return   False  ;}  Int  Main (){  Int  T; Bool  Over;  Char Temp [ 3  ]; Scanf (  "  % D  " ,& T );  While (T -- ) {Memset (G,  0 , Sizeof  (G); Box [  0 ] ='  O  ' , Box [ 1 ] = '  K  ' , Box [ 2 ] = '  \ 0  '  ; Over = False  ; Scanf (  "  % D " , & A, & B ); //  A is wide, B is high Scanf ( "  % D  " , & N, & M ); //  N indicates the number of robots, and M indicates the number of commands.          For ( Int I = 1 ; I <= N; ++ I) {scanf (  "  % D % s " , & X [I], & Y [I], temp); G [x [I] [Y [I] = I;  Switch (Temp [ 0  ]) {  Case   '  W  ' : D [I] = 0 ; Break  ;  Case   ' N  ' : D [I] = 1 ; Break  ;  Case   '  E  ' : D [I] = 2 ; Break  ;  Case   '  S  ' : D [I] =3 ; Break  ;}}  While (M -- ){  Int  Who, kind; scanf (  "  % D % S % d  " , & M. No, M. Op ,& M. Times );  If  (Over ){  Continue ;}  If  (Update (WHO, kind) {over = True  ;  If (Kind = 1  ) {Sprintf (box,  "  Robot % d crashes into the wall  "  , M. No );}  Else  {Sprintf (box, "  Robot % d crashes into robot % d  "  , M. No, WHO) ;}} puts (box );}  Return   0  ;} 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.