Advertisement
Guest User

Untitled

a guest
Apr 28th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. #include <cstdio> 
  4.  
  5. using namespace std;
  6.  
  7. int fx[6]={1,-1,0,0,0,0};
  8. int fy[6]={0,0,1,-1,0,0};
  9. int fz[6]={0,0,0,0,1,-1};
  10. char s[30];
  11. int vis[4][4][4];
  12. bool judge(int x,int y,int z)
  13. {
  14. if(x<0||x>2||y<0||y>2||z<0||z>2||vis[x][y][z])
  15. return false;
  16. return true;
  17. }
  18. bool dfs(int x,int y,int z,int icount,int pos)
  19. {
  20. char c=s[icount];
  21. int px = x+fx[pos];
  22. int py = y+fy[pos];
  23. int pz = z+fz[pos];
  24. if(icount==27)
  25. return judge(px,py,pz);
  26. if (!judge(px,py,pz))
  27. return false;
  28. if(c=='I')
  29. {
  30. vis[px][py][pz] = 1;
  31. if(dfs(px,py,pz,icount+1,pos))
  32. return true;
  33. else
  34. {
  35. vis[px][py][pz] =0;
  36. return false;
  37. }
  38. }
  39. else if(c=='L')
  40. {
  41. vis[px][py][pz] = 1;
  42. for (int i=0;i<6;i++)
  43. {
  44. if (i!=pos)
  45. {
  46. if(dfs(px,py,pz,icount+1,i))
  47. return true;
  48. }
  49. }
  50. vis[px][py][pz] =0;
  51. return false;
  52. }
  53. }
  54. int main()
  55. {
  56. while(~scanf("%s",s+1))
  57. {
  58. memset(vis,0,sizeof(vis));
  59. bool flag = false;
  60. for (int i=2;i<27;++i)
  61. if(s[i]=='E')
  62. {
  63. flag = true;
  64. break;
  65. }
  66. if(flag)
  67. {
  68. cout<<"NO";
  69. continue;
  70. }
  71. for (int i=0;i<3;++i)
  72. {
  73. for (int j=0;j<3;++j)
  74. {
  75. for (int k=0;k<3;++k)
  76. {
  77. vis[i][j][k]=1;
  78. if(dfs(i,j,k,2,0))
  79. {
  80. flag =true;
  81. break;
  82. }
  83. vis[i][j][k]=0;
  84. }
  85. if(flag)
  86. break;
  87. }
  88. if(flag)
  89. break;
  90. }
  91. if(flag)
  92. cout<<"YES";
  93. else
  94. cout<<"NO";
  95. }
  96. return 0;
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement