Advertisement
iamyeasin

Mutant

Mar 24th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define black 1
  3. #define white 2
  4. #define none 0
  5. #define MAX 10000000
  6. #define dbg cout << "DEBUG IS SHOWING " << endl;
  7.  
  8. int dx[] = { +1, -1, -0 , +0 };
  9. int dy[] = { +0, -0, +1, -1 };
  10.  
  11. using namespace std;
  12.  
  13. long n,m,xi,yi,isLost = false, lostx,losty ;
  14. char iDir;
  15. int grid[100][100]; bool flag[100][100];
  16.  
  17. char dir[] = { 'N', 'E', 'S', 'W' };
  18.  
  19. bool isok( int x, int y ){
  20. return (x >= 0 && x<=n && y>=0 && y<=m);
  21. }
  22.  
  23.  
  24. bool isSafe( int x, int y ){
  25. if( flag[x][y] == 0) return 1;
  26. return 0;
  27. }
  28.  
  29. int main(){
  30.  
  31. #ifndef ONLINE_JUDGE
  32. freopen( "in.txt","rt",stdin );
  33. #endif
  34.  
  35. cin >> n >> m;
  36. for( int i=0; i<=n; i++ ){
  37. for( int j=0; j<=m; j++ ){
  38. flag[i][j] = 0;
  39. }
  40. }
  41. while( scanf( "%ld %ld %c",&xi,&yi, &iDir ) != EOF ){
  42. // cout << xi << " " << yi << " " << iDir << endl;
  43. char cmd[1024];
  44. scanf("%s",cmd);
  45. int curDir = 0;
  46.  
  47. for( int i=0; i<4; i++ ) {
  48. if( dir[i] == iDir ){
  49. curDir = i; break;
  50. }
  51. }
  52. cout << dir[curDir] << endl;
  53. int tx,ty;
  54. for( int i=0; cmd[i]; i++ ){
  55. tx = xi; ty = yi;
  56.  
  57. if( cmd[i] == 'R' ){
  58. curDir = (curDir+1)%4;
  59. }
  60. else if( cmd[i] == 'L' ){
  61. curDir = ( (curDir-1) >= 0 ) ? curDir-1 : 3;
  62. }
  63. else if ( cmd[i] == 'F' ){
  64. if( curDir == 0 ) yi++;
  65. else if ( curDir == 1 ) xi++;
  66. else if ( curDir == 2 ) yi--;
  67. else if( curDir == 3 ) xi--;
  68. //
  69. // cout << " T " << xi << " " << yi << endl;
  70.  
  71. if( flag[yi][xi] == 1) {
  72. xi = tx; yi = ty;
  73. cout << xi << " " << yi << endl;
  74. continue;
  75. }
  76.  
  77. if( ((xi > n || yi > m) && !flag[xi][yi]) || (xi < 0 || yi < 0 )){
  78. cout << tx << " " << ty << " " << dir[curDir] << " LOST" << endl;
  79. isLost = true;
  80. if( xi >= 0 && yi >= 0 )flag[yi][xi] = 1;
  81. break;
  82. }
  83. }
  84. cout << cmd[i] << " " << xi << " " << yi << " " << dir[curDir] <<endl;
  85. }
  86.  
  87. if( !isLost )
  88. cout << xi << " " << yi << " " << dir[curDir] << endl;
  89.  
  90. isLost = false;
  91. }
  92.  
  93.  
  94. return 0;
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement