"Hdoj" 2414 chessboard Dance

Source: Internet
Author: User

Simple DFS.

1 /*2414*/2#include <cstdio>3#include <cstring>4#include <cstdlib>5 6 Const intn =8;7 Charmap[Ten][Ten];8 intx, y, D;9 Chardirs[5] ="^v<>";Ten intdir[4][2] = { One-1,0,1,0,0,-1,0,1 A }; - inttdir[4][3] = { -     2,3,1,3,2,0,1,0,3,0,1,2 the }; -  -InlineBOOLCheckintXinty) { -     returnx<0|| X>=n | | y<0|| y>=N; + } -  + voidDfsintXinty) { A     intI, J, K; at     intxx, yy; -  -xx = x + dir[d][0]; -yy = y + dir[d][1]; -     if(check (xx, yy)) -         return ; in     if(Map[xx][yy] = ='.') { -MAP[XX][YY] =Map[x][y]; toMap[x][y] ='.'; +}Else { - dfs (xx, yy); theMAP[XX][YY] =Map[x][y]; *Map[x][y] ='.'; $     }Panax Notoginseng } -  the intMain () { +     intI, J, K; A     Charcmd[Ten]; the     intxx, yy; +  - #ifndef Online_judge $Freopen ("data.in","R", stdin); $Freopen ("Data.out","W", stdout); -     #endif -  the      while(SCANF ("%s", map[0]) !=EOF) { -         if(map[0][0]=='-'&& map[0][1]=='-'&& map[0][2]==' /')Wuyi              Break; the          for(i=1; i<8; ++i) -scanf"%s", Map[i]); Wu          for(i=0; i<8; ++i) { -              for(j=0; j<8; ++j) { About                 if(Map[i][j] = ='^') { $x =i; -y =J; -D =0; -}Else if(Map[i][j] = ='v') { Ax =i; +y =J; theD =1; -}Else if(Map[i][j] = ='<') { $x =i; they =J; theD =2; the}Else if(Map[i][j] = ='>') { thex =i; -y =J; inD =3; the                 } the             } About         } the          while(SCANF ("%s", cmd)!=eof && cmd[0]!='#') { the             if(cmd[0] =='m') { the                 //Move +scanf"%d", &k); -                  while(k--) { thexx = x + dir[d][0];Bayiyy = y + dir[d][1]; the                     if(check (xx, yy)) the                          Break; - dfs (x, y); -x =xx; they =yy; the                 } the}Else { the                 //Turn -scanf"%s", cmd); the                 if(cmd[0] =='L') { theD = tdir[d][0]; the}Else if(cmd[0] =='R') {94D = tdir[d][1]; the}Else { theD = tdir[d][2]; the                 }98             } About         } -Map[x][y] =Dirs[d];101          for(i=0; i<8; ++i) {102map[i][8] =' /';103 puts (map[i]);104         } thePutchar ('\ n');106     }107 108     return 0;109}

"Hdoj" 2414 chessboard Dance

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.