Advertisement
Guest User

Untitled

a guest
Apr 30th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. #include <cstdio>
  2. #include <cstring>
  3. #include <cassert>
  4. #include <iostream>
  5. #include <algorithm>
  6. #include <vector>
  7. #include <set>
  8.  
  9. #define r first
  10. #define c second
  11. #define FOR(i, a, b) for (int i = (a); i < (b); ++i)
  12. #define REP(i, n) FOR (i, 0, n)
  13. #define _ << " _ " <<
  14. #define TRACE(x) cerr << #x << " = " << x << endl
  15. #define debug(...) fprintf(stderr, __VA_ARGS__)
  16. //#define debug
  17. //#define TRACE(x)
  18.  
  19. using namespace std;
  20. using pii = pair<int, int>;
  21.  
  22. typedef long long llint;
  23.  
  24. const int DR[] = {-1, 0, 1, 0};
  25. const int DC[] = {0, 1, 0, -1};
  26. const int MAXN = 55;
  27.  
  28. int get(char c, int curr) {
  29. if (c == 'L')
  30. return (curr + 3) % 4;
  31. return (curr + 1) % 4;
  32. }
  33.  
  34. char a[MAXN][MAXN];
  35. int bio[MAXN][MAXN], cookie;
  36. int n = 50;
  37.  
  38. bool in(int r, int c) {
  39. if (r < 0 || c < 0 || r >= n || c >= n) return false;
  40. return true;
  41. }
  42.  
  43. bool move(int r, int c, int dir) {
  44. while (true) {
  45. int nr = DR[dir];
  46. int nc = DC[dir];
  47.  
  48. if (!in(nr,nc))
  49. return false;
  50. if (a[nr][nc] == '#')
  51. break;
  52. r = nr;
  53. c = nc;
  54. }
  55. return true;
  56. }
  57.  
  58. bool solve(string s) {
  59. ++cookie;
  60. REP(r, MAXN) REP(c, MAXN) a[r][c] = '.';
  61.  
  62. int sr = rand() % 2 ? 0 : n - 1;
  63. a[sr][0] = '@';
  64. bio[sr][0] = cookie;
  65.  
  66. int dir = 1;
  67.  
  68. bool flag = true;
  69.  
  70. int r = sr, c = 0;
  71. REP(i, (int)s.size()) {
  72. int tr = r, tc = c;
  73. vector<pii> v;
  74.  
  75. bool wall = false;
  76. while (in(tr,tc)) {
  77. if (bio[tc][tc] != cookie)
  78. v.push_back({tr,tc});
  79. int nr = tr + DR[dir];
  80. int nc = tc + DC[dir];
  81. if (a[nr][nc] == '#') {
  82. wall = true;
  83. break;
  84. }
  85. tr = nr;
  86. tc = nc;
  87. }
  88.  
  89. if (wall) {
  90. r = tr;
  91. c = tc;
  92. dir = get(s[i]);
  93. } else {
  94. random_shuffle(v.begin(), v.end());
  95. if (v.empty()) {
  96. flag = false;
  97. break;
  98. }
  99. a[v[0].r][v[0].c] = '#';
  100. move(r, c, dir);
  101. }
  102. }
  103.  
  104. if (!flag) return false;
  105.  
  106. return move(r, c, dir);
  107. }
  108.  
  109. int main(void) {
  110.  
  111. return 0;
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement