Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 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 FOR(i, a, b) for (int i = (a); i < (b); ++i)
  10. #define REP(i, n) FOR (i, 0, n)
  11. #define _ << " _ " <<
  12. #define TRACE(x) cerr << #x << " = " << x << endl
  13. #define debug(...) fprintf(stderr, __VA_ARGS__)
  14. //#define debug
  15. //#define TRACE(x)
  16.  
  17. using namespace std;
  18.  
  19. typedef long long llint;
  20.  
  21. const int MAX = 5005 * 3;
  22.  
  23. int cnt[4];
  24. int poz;
  25. vector <int> R;
  26. int bio[MAX];
  27. int n;
  28.  
  29. void go(int x) {
  30. assert(cnt[abs(x)]--);
  31. poz += x;
  32. TRACE(poz);
  33. assert(poz >= 0 && poz < n);
  34. assert(!bio[poz]++);
  35. R.push_back(poz);
  36. }
  37.  
  38. void go_A() {
  39. go(3); go(-2); go(3); go(-2); go(3);
  40. }
  41.  
  42. void go_B() {
  43. go(3); go(-2); go(1); go(2);
  44. }
  45.  
  46. void fin_3_0() { //ima trojaka, nema dvojki
  47. assert(cnt[1] >= 2 && !cnt[2]);
  48. for (; cnt[1] > 2; ) go(1);
  49.  
  50. int k = cnt[3] / 3;
  51. if (cnt[3] % 3 == 0) {
  52. REP(i, k) go(3);
  53. go(1);
  54. REP(i, k) go(-3);
  55. go(1);
  56. REP(i, k) go(3);
  57. }
  58. else if (cnt[3] % 3 == 1) {
  59. REP(i, k+1) go(3);
  60. go(-1);
  61. REP(i, k) go(-3);
  62. go(-1);
  63. REP(i, k) go(3);
  64. }
  65. else {
  66. REP(i, k+1) go(3);
  67. go(1);
  68. REP(i, k+1) go(-3);
  69. go(1);
  70. REP(i, k) go(3);
  71. }
  72. }
  73.  
  74. void fin_3_1() { //ima trojaka, nema dvojaka
  75. assert(cnt[2] == 1 && cnt[1] > 0);
  76. for (; cnt[1] > 1; ) go(1);
  77.  
  78. int k = cnt[3] / 3;
  79. if (cnt[3] % 3 == 0) {
  80. REP(i, k) go(3);
  81. go(2);
  82. REP(i, k) go(-3);
  83. go(1);
  84. REP(i, k) go(3);
  85. }
  86. }
  87.  
  88. void fin_2() { //nema trojaka, ima dvojaka
  89. for (; cnt[1] > 1; ) go(1);
  90. int kol = (cnt[2]+1)/2, ost = cnt[2] % 2;
  91. REP(i, kol) go(2);
  92. if (ost) go(-1);
  93. else go(1);
  94.  
  95. for (; cnt[2]; ) go(-2);
  96. }
  97.  
  98. void print() {
  99. for (auto it : R)
  100. printf("%d ", it);
  101. printf("\n");
  102. }
  103.  
  104. int main(void) {
  105. poz = 0;
  106. bio[0] = 1;
  107. R.push_back(0);
  108.  
  109. cnt[1] = 3;
  110. cnt[2] = 1;
  111. cnt[3] = 6;
  112. n = cnt[1] + cnt[2] + cnt[3] + 1;
  113. fin_3_1();
  114. print();
  115.  
  116.  
  117. return 0;
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement