HDU 2414 chessboard Dance (forced simulation)

Source: Internet
Author: User

Link: HDU 2414 chessboard dance

Question: give a picture, >,<^, V indicates the direction of the person's face. The letter is equivalent to the box. The box can be pushed out of the Boundary. The person guarantees that no boundary is made. Enter the following command, follow the instructions to output the chart status at the end;


Simulate it by force. Pay attention to the following cases.

>t.p.p.p...a...............bfg.y...c......d.......e............move 3turn rightmove 3turn leftmove 3turn leftmove 3#


AC code:


# Include <stdio. h> # include <string. h >#include <algorithm> # include <queue> using namespace STD; const int maxn = 20; char MP [maxn] [maxn]; queue <char> q; int get_dir (int x, int y) {If (MP [x] [Y] = '^') return 1; else if (MP [x] [Y] = '>') return 2; else if (MP [x] [Y] = 'V') return 3; else if (MP [x] [Y] = '<') return 4;} void out () {int I, J; // printf ("------------------- \ n"); for (I = 0; I <8; I ++) {for (j = 0; j <8; j ++) printf ("% C", MP [I] [J ]); Printf ("\ n");} printf ("\ n");} int main () {int I, j; int Dir, X, Y; char SCR [20]; while (scanf ("% s", MP [0])! = EOF) {If (strcmp (MP [0], "--") = 0) break; while (! Q. empty () Q. pop (); for (I = 1; I <8; I ++) scanf ("% s", MP [I]); for (I = 0; I <8; I ++) {for (j = 0; j <8; j ++) {If (MP [I] [J] = '>' | MP [I] [J] = '^' | MP [I] [J] = '<' | MP [I] [J] = 'V ') {x = I; y = J; Dir = get_dir (x, y); break ;}}// out (); While (1) {scanf ("% s", Scr); If (strcmp (SCR, "#") = 0) break; while (! Q. empty () Q. pop (); If (strcmp (SCR, "move") = 0) {int SS; scanf ("% d", & SS); If (DIR = 1) // up {int temp; If (SS> = x )//! Exit the {temp = x; for (I = x; I> = 0; I --) MP [I] [Y] = '. '; MP [x = 0] [Y] =' ^ ';} else {MP [x] [Y] = '. '; int temp = X-1; int cont = SS; while (cont --) {While (MP [temp] [Y]! = '. '& Temp> = 0) {q. push (MP [temp] [Y]); MP [temp] [Y] = '. '; temp --;} temp = x-ss; MP [x = temp --] [Y] =' ^ '; (; temp> = 0 &&! Q. empty (); temp --) {MP [temp] [Y] = Q. front (); q. pop () ;}// out () ;}else if (DIR = 2) // to the right {int temp; If (SS> = 7-y )//! Exit the {temp = 7-y; for (I = y; I <8; I ++) MP [x] [I] = '. '; MP [x] [Y = 7] ='> ';} else {MP [x] [Y] = '. '; int temp = Y + 1; int cont = SS; while (cont --) {While (MP [x] [temp]! = '. '& Temp <8) {q. push (MP [x] [temp]); MP [x] [temp] = '. '; temp ++;} temp = Y + SS; MP [x] [Y = temp ++] ='> '; (; temp <8 &&! Q. empty (); temp ++) {MP [x] [temp] = Q. front (); q. pop () ;}// out () ;}else if (DIR = 3) // down {int temp; If (SS> = 7-x )//! Exit the {temp = 7-x; for (I = x; I <8; I ++) MP [I] [Y] = '. '; MP [x = 7] [Y] = 'V';} else {MP [x] [Y] = '. '; int temp = x + 1; int cont = SS; while (cont --) {While (MP [temp] [Y]! = '. '& Temp <8) {q. push (MP [temp] [Y]); MP [temp] [Y] = '. '; temp ++;} temp = x + SS; MP [x = temp ++] [Y] = 'V'; (; temp <8 &&! Q. empty (); temp ++) {MP [temp] [Y] = Q. front (); q. pop () ;}// out () ;}else if (DIR = 4) // to the left {int temp; If (SS> = y )//! Exit the {temp = y; for (I = y; I> = 0; I --) MP [x] [I] = '. '; MP [x] [Y = 0] =' <';} else {MP [x] [Y] = '. '; int temp = Y-1; int cont = SS; while (cont --) {While (MP [x] [temp]! = '. '& Temp> = 0) {q. push (MP [x] [temp]); MP [x] [temp] = '. '; temp --;} temp = Y-ss; MP [x] [Y = temp --] =' <'; (; temp> = 0 &&! Q. empty (); temp --) {MP [x] [temp] = Q. front (); q. pop () ;}// out () ;}} else if (strcmp (SCR, "Turn") = 0) {char CC [20]; scanf ("% s", CC); If (strcmp (CC, "Left") = 0) {If (DIR = 1) dir = 4, MP [x] [Y] = '<'; else if (DIR = 2) dir = 1, MP [x] [Y] = '^ '; else if (DIR = 3) dir = 2, MP [x] [Y] = '>'; else if (DIR = 4) dir = 3, MP [x] [Y] = 'V';} else if (strcmp (CC, "right") = 0) {If (DIR = 1) dir = 2, MP [x] [Y] = '>'; else if (DIR = 2) dir = 3, MP [x] [Y] = 'V '; else if (DIR = 3) dir = 4, MP [x] [Y] = '<'; else if (DIR = 4) dir = 1, MP [x] [Y] = '^';} else if (strcmp (CC, "back") = 0) {If (DIR = 1) dir = 3, MP [x] [Y] = 'V'; else if (DIR = 2) dir = 4, MP [x] [Y] = '<'; else if (DIR = 3) dir = 1, MP [x] [Y] = '^'; else if (DIR = 4) dir = 2, MP [x] [Y] = '>';} // out () ;}} out ();} return 0 ;}/*..... c... P .. A .. TD...> t. PR .... AP. pp. d. C ........ p. R ................ move 5 ..... c... P .. A .. TD...> t. PR .... AP. pp. d. C ........ p. R ................ move 1 turn leftmove 99 turn backmove 6 #..... c... P ..... TD .... TPR ..... p. pp. d. C ........ p. R .... V ....... a...> t. p. p. p... A ............... BFG. y... C ...... d ....... E ............ move 3 turn rightmove 3 turn leftmove 3 turn leftmove 3 #.> ta. CB ....................................... .................. move 3 #*/


HDU 2414 chessboard Dance (forced simulation)

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.