Advertisement
filashkov

Untitled

Apr 18th, 2021
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.39 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <set>
  5.  
  6. using namespace std;
  7.  
  8. enum
  9. {
  10. UP = 0,
  11. RIGHT,
  12. DOWN,
  13. LEFT,
  14. EDGE_SIZE = 3,
  15. FRONT_EDGE = 0,
  16. BACK_EDGE,
  17. LEFT_EDGE,
  18. RIGHT_EDGE,
  19. LOWER_EDGE,
  20. UPPER_EDGE
  21. };
  22.  
  23. void f(int y, int x, int dy, int dx)
  24. {
  25. if ((y >= -EDGE_SIZE - EDGE_SIZE / 2) && (y < -EDGE_SIZE / 2))
  26. {
  27. if (x == EDGE_SIZE / 2 + 1)
  28. {
  29. x--;
  30. swap(y, x);
  31. swap(dy, dx);
  32. }
  33. else if (x == -EDGE_SIZE / 2 - 1)
  34. {
  35. x++;
  36. dx *= -1;
  37. swap(y, x);
  38. swap(dy, dx);
  39. }
  40. }
  41. else if ((y > EDGE_SIZE / 2) && (y <= EDGE_SIZE + EDGE_SIZE / 2))
  42. {
  43. if (x == EDGE_SIZE / 2 + 1)
  44. {
  45. x--;
  46. dx *= -1;
  47. swap(y, x);
  48. swap(dy, dx);
  49. }
  50. else if (x == -EDGE_SIZE / 2 - 1)
  51. {
  52. x++;
  53. swap(y, x);
  54. swap(dy, dx);
  55. }
  56. }
  57. }
  58.  
  59. void fix(int& x, int& y, int& dx, int& dy)
  60. {
  61. if (y == EDGE_SIZE * 2 + EDGE_SIZE / 2 + 1)
  62. {
  63. y -= 4 * EDGE_SIZE;
  64. }
  65. else if (y == -EDGE_SIZE - EDGE_SIZE / 2 - 1)
  66. {
  67. y += 4 * EDGE_SIZE;
  68. }
  69. else if (dx == 0)
  70. {
  71. if ((x >= -EDGE_SIZE - EDGE_SIZE / 2) && (x < -EDGE_SIZE / 2))
  72. {
  73. if (y == EDGE_SIZE / 2 + 1)
  74. {
  75. y--;
  76. swap(x, y);
  77. swap(dx, dy);
  78. }
  79. else if (y == -EDGE_SIZE / 2 - 1)
  80. {
  81. y++;
  82. dy *= -1;
  83. swap(x, y);
  84. swap(dx, dy);
  85. }
  86. }
  87. else if ((x > EDGE_SIZE / 2) && (x <= EDGE_SIZE + EDGE_SIZE / 2))
  88. {
  89. if (y == EDGE_SIZE / 2 + 1)
  90. {
  91. y--;
  92. dy *= -1;
  93. swap(x, y);
  94. swap(dx, dy);
  95. }
  96. else if (y == -EDGE_SIZE / 2 - 1)
  97. {
  98. y++;
  99. swap(x, y);
  100. swap(dx, dy);
  101. }
  102. }
  103. }
  104. else if (dy == 0)
  105. {
  106. if ((y >= -EDGE_SIZE - EDGE_SIZE / 2) && (y < -EDGE_SIZE / 2))
  107. {
  108. if (x == EDGE_SIZE / 2 + 1)
  109. {
  110. x--;
  111. swap(y, x);
  112. swap(dy, dx);
  113. }
  114. else if (x == -EDGE_SIZE / 2 - 1)
  115. {
  116. x++;
  117. dx *= -1;
  118. swap(y, x);
  119. swap(dy, dx);
  120. }
  121. }
  122. else if ((y > EDGE_SIZE / 2) && (y <= EDGE_SIZE + EDGE_SIZE / 2))
  123. {
  124. if (x == EDGE_SIZE / 2 + 1)
  125. {
  126. x--;
  127. dx *= -1;
  128. swap(y, x);
  129. swap(dy, dx);
  130. }
  131. else if (x == -EDGE_SIZE / 2 - 1)
  132. {
  133. x++;
  134. swap(y, x);
  135. swap(dy, dx);
  136. }
  137. }
  138. else if (x == -EDGE_SIZE - EDGE_SIZE / 2 - 1)
  139. {
  140. dx *= -1;
  141. x += 1 + EDGE_SIZE;
  142. y = 2 * EDGE_SIZE - y;
  143. }
  144. else if (x == EDGE_SIZE + EDGE_SIZE / 2 + 1)
  145. {
  146. dx *= -1;
  147. x -= 1 - EDGE_SIZE;
  148. y = 2 * EDGE_SIZE - y;
  149. }
  150. else if (x == -EDGE_SIZE / 2 - 1)
  151. {
  152. dx *= -1;
  153. y -= 2 * EDGE_SIZE;
  154. y *= -1;
  155. x -= EDGE_SIZE - 1;
  156. }
  157. else if (x == EDGE_SIZE / 2 + 1)
  158. {
  159. dx *= -1;
  160. y -= 2 * EDGE_SIZE;
  161. y *= -1;
  162. x += EDGE_SIZE - 1;
  163. }
  164. }
  165.  
  166. }
  167.  
  168. vector<int>& operator+= (vector<int>& target, const vector<int>& adding)
  169. {
  170. auto adding_it = adding.begin();
  171. for (auto it = target.begin(); it != target.end(); ++it, ++adding_it) {
  172. *it += *adding_it;
  173. }
  174. return target;
  175. }
  176.  
  177. vector<int>& operator-= (vector<int>& target, const vector<int>& subtrahend)
  178. {
  179. auto subtrahend_it = subtrahend.begin();
  180. for (auto it = target.begin(); it != target.end(); ++it, ++subtrahend_it) {
  181. *it -= *subtrahend_it;
  182. }
  183. return target;
  184. }
  185.  
  186. int
  187. fix_is_necessary(const vector<int>& coordinates)
  188. {
  189. for (int i = 0; i < coordinates.size(); i++) {
  190. if ((coordinates[i] < 0) && (coordinates[i] >= EDGE_SIZE)) {
  191. return i;
  192. }
  193. }
  194. return -1;
  195. }
  196.  
  197. void
  198. coordinates_changing(vector<int>& coordinates, vector<int>& direction)
  199. {
  200. coordinates += direction;
  201. int index_to_fix;
  202. if ((index_to_fix = fix_is_necessary(coordinates)) == -1) {
  203. return;
  204. }
  205. coordinates -= direction;
  206.  
  207. }
  208.  
  209.  
  210.  
  211. inline void
  212. change_coordinates(int& x, int& y, int& z, int& edge, const int direction)
  213. {
  214.  
  215. }
  216.  
  217. inline void
  218. process(const char command, set<int>& visited)
  219. {
  220. auto encode_coordinates = [](int x, int y, int z) { return x * EDGE_SIZE * EDGE_SIZE + y * EDGE_SIZE + z; };
  221. static int x = 1, y = 1, z = 0;
  222. static int face_mode = 1;
  223. static int direction = 0;
  224. visited.insert(encode_coordinates(x, y, z));
  225. switch (command)
  226. {
  227. case 'R':
  228. direction += 1;
  229. direction %= (LEFT + 1);
  230. break;
  231. case 'L':
  232. direction -= 1;
  233. direction += LEFT + 1;
  234. direction %= (LEFT + 1);
  235. break;
  236. case 'S':
  237. return;
  238. }
  239. change_coordinates(x, y, z, edge, direction);
  240. }
  241.  
  242. int main()
  243. {
  244. string input;
  245. set<int> visited;
  246. cin >> input;
  247. for (auto elem : input)
  248. {
  249. process(elem, visited);
  250. }
  251. cout << visited.size() << endl;
  252. return 0;
  253. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement