dimuster

acmp 341

Jan 15th, 2021 (edited)
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.01 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int next(int a) {
  6.     bool forbidden[10] = {};
  7.     {
  8.         int t = a;
  9.         do {
  10.             forbidden[t % 10] = true;
  11.             t /= 10;
  12.         } while (t != 0);
  13.     }
  14.     for (int i = a + 1; ; i++) {
  15.         int t = i;
  16.         bool good = true;
  17.         do {
  18.             if (forbidden[t % 10]) {
  19.                 good = false;
  20.             }
  21.             t /= 10;
  22.         } while (t != 0);
  23.         if (good)
  24.             return i;
  25.     }
  26. }
  27.  
  28. void research() {
  29.     int a = 0;
  30.     for (int i = 1; i <= 500; i++) {
  31.         cout << i << " -> " << a << endl;
  32.         a = next(a);
  33.     }
  34. }
  35.  
  36. int main() {
  37.     /*research();*/
  38.     int n;
  39.     cin >> n;
  40.     if (n < 21) {
  41.         int a = 0;
  42.         for (int i = 1; i < n; i++) {
  43.             a = next(a);
  44.         }
  45.         cout << a;
  46.     } else {
  47.         int firstDigit = (n - 21) % 8 + 2;
  48.         int secondDigit = (n - 21) % 2;
  49.         int secondDigitCount = (n - 21) / 8 + 2;
  50.         cout << firstDigit;
  51.         for (int i = 0; i < secondDigitCount; i++) {
  52.             cout << secondDigit;
  53.         }
  54.     }
  55.  
  56.     return 0;
  57. }
  58.  
  59.  
  60. /*
  61. research():
  62. 1 -> 0
  63. 2 -> 1
  64. 3 -> 2
  65. 4 -> 3
  66. 5 -> 4
  67. 6 -> 5
  68. 7 -> 6
  69. 8 -> 7
  70. 9 -> 8
  71. 10 -> 9
  72. 11 -> 10
  73. 12 -> 22
  74. 13 -> 30
  75. 14 -> 41
  76. 15 -> 50
  77. 16 -> 61
  78. 17 -> 70
  79. 18 -> 81
  80. 19 -> 90
  81. 20 -> 111
  82.  
  83. 21 -> 200
  84. 22 -> 311
  85. 23 -> 400
  86. 24 -> 511
  87. 25 -> 600
  88. 26 -> 711
  89. 27 -> 800
  90. 28 -> 911
  91.  
  92. 29 -> 2000
  93. 30 -> 3111
  94. 31 -> 4000
  95. 32 -> 5111
  96. 33 -> 6000
  97. 34 -> 7111
  98. 35 -> 8000
  99. 36 -> 9111
  100.  
  101. 37 -> 20000
  102. 38 -> 31111
  103. 39 -> 40000
  104. 40 -> 51111
  105. 41 -> 60000
  106. 42 -> 71111
  107. 43 -> 80000
  108. 44 -> 91111
  109.  
  110. 45 -> 200000
  111. 46 -> 311111
  112. 47 -> 400000
  113. 48 -> 511111
  114. 49 -> 600000
  115. 50 -> 711111
  116. 51 -> 800000
  117. 52 -> 911111
  118.  
  119. 53 -> 2000000
  120. 54 -> 3111111
  121. 55 -> 4000000
  122. 56 -> 5111111
  123. 57 -> 6000000
  124. 58 -> 7111111
  125. 59 -> 8000000
  126. 60 -> 9111111
  127.  
  128. 61 -> 20000000
  129. 62 -> 31111111
  130. 63 -> 40000000
  131. 64 -> 51111111
  132. 65 -> 60000000
  133. 66 -> 71111111
  134. 67 -> 80000000
  135. 68 -> 91111111
  136.  
  137. TIME LIMIT
  138.  
  139.  
  140.  
  141. */
Add Comment
Please, Sign In to add comment