Advertisement
mrlolthe1st

Untitled

Mar 18th, 2021
962
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.58 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #pragma GCC Optimize("Ofast")
  3. #include <iostream>
  4. #include <vector>
  5. #include <set>
  6. #include <string>
  7. #include <time.h>
  8. #include <unordered_set>
  9. #include <map>
  10. #include <queue>
  11. #include <algorithm>
  12. #include <fstream>
  13. #include <cstddef>
  14. #include <cstdio>
  15. #include <iostream>
  16. #include <memory>
  17. #include <stdexcept>
  18. #include <string>
  19. #include <array>
  20. using namespace std;
  21.  
  22. #define vi vector<int>
  23. #define vec vector
  24. int c[1024];
  25. int go(vi& a) {
  26.     int r = 0;
  27.     for (int i = 0; i < a.size(); ++i)
  28.         r += (1 << (a[i] - 1));
  29.     return r;
  30. }
  31. int code(vi& a) {
  32.     int r = go(a);
  33.     return c[r];
  34. }
  35.  
  36. int decode(vi& a) {
  37.     int r = go(a);
  38.     for (auto& e : a) {
  39.         int w = r ^ (1 << (e - 1));
  40.         if (e == c[w]) {
  41.             return e;
  42.         }
  43.     }
  44. }
  45.  
  46. int popcount(int x) {
  47.     int r = 0;
  48.     while (x) r += x & 1, x >>= 1;
  49.     return r;
  50. }
  51.  
  52. int gen(int x, int nq = -1) {
  53.     for (int i = 0; i < 10; ++i)
  54.         if (!((1 << i) & x) && i != nq) {
  55.             int cnt = 0;
  56.             c[x] = i + 1;
  57.             for (int j = 0; j < 10; ++j)
  58.                 if ((1 << j) & x) {
  59.                     int nw = (1 << i) | (x ^ (1 << j));
  60.                     if (!c[nw])
  61.                         c[nw] = gen(nw, j);
  62.                     if (c[nw] != j + 1)
  63.                         cnt++;
  64.                 }
  65.             if (cnt == 3)
  66.                 return i + 1;
  67.         }
  68. }
  69.  
  70. int main() {
  71.     vi x;
  72.     for (int i = 0; i < 1024; ++i) {
  73.         if (popcount(i) == 3) {
  74.             c[i] = gen(i);
  75.         }
  76.     }
  77.     for (int i = 0; i < 1024; ++i) {
  78.         if (popcount(i) == 3) {
  79.             vi a;
  80.             for (int j = 0; j < 10; ++j)
  81.                 if ((1 << j) & i) a.push_back(j + 1);
  82.             int v = code(a);
  83.             a.push_back(v);
  84.             if (v != decode(a)) {
  85.                 v = v; cout << "err"; exit(-1);
  86.             }
  87.         }
  88.     }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement