Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.49 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. using ll = long long;
  4. #define int ll
  5. #define all(x) x.begin(), x.end()
  6. #define x first
  7. #define y second
  8. #define mp make_pair
  9. #define mt make_tuple
  10.  
  11. const int N = 20;
  12. int n = 8;
  13.  
  14. bool ok(int i, int j) {
  15.     return 0 <= i && i < N && 0 <= j && j < N;
  16. }
  17.  
  18. int p[N][N], q[N][N], col[N][N];
  19. int prefp[N][N], prefq[N][N];
  20.  
  21. void prepare() {
  22.     fill_n(q[0], N * N, 0);
  23.     fill_n(prefp[0], N * N, 0);
  24.     fill_n(prefq[0], N * N, 0);
  25.     for (int i = 0; i < n; ++i) {
  26.         for (int j = 0; j < n; ++j) {
  27.             q[i + j][i + n - j] = p[i][j];
  28.         }
  29.     }
  30.     for (int i = 0; i < N - 1; ++i) {
  31.         for (int j = 0; j < N - 1; ++j) {
  32.             prefp[i + 1][j + 1] = prefp[i + 1][j] + prefp[i][j + 1] - prefp[i][j] + (p[i][j] != 0);
  33.             prefq[i + 1][j + 1] = prefp[i + 1][j] + prefp[i][j + 1] - prefp[i][j] + (q[i][j] != 0);
  34.         }
  35.     }
  36. }
  37. int sump(int a, int b, int c, int d) {
  38.     if (a > c) {
  39.         swap(a, c);
  40.     }
  41.     if (b > d) {
  42.         swap(b, d);
  43.     }
  44.     ++c, ++d;
  45.     return prefp[c][d] - prefp[a][d] - prefp[c][b] + prefp[a][b];
  46. }
  47. int sumq(int a, int b, int c, int d) {
  48.     if (a > c) {
  49.         swap(a, c);
  50.     }
  51.     if (b > d) {
  52.         swap(b, d);
  53.     }
  54.     ++c, ++d;
  55.     return prefq[c][c] - prefq[a][d] - prefq[c][b] + prefq[a][b];
  56. }
  57.  
  58. bool hit(int a, int b, int c, int d) {
  59.     int tp = p[a][b];
  60.     if (a == c && b == d) {
  61.         return false;
  62.     }
  63.     if (tp == 0) {
  64.         return false;
  65.     } else if (tp == 1) {
  66.         if (a == c || b == d) {
  67.             return sump(a, b, c, d) == 2;
  68.         } else if (a + b == c + d || a - b == c - d) {
  69.             return sumq(a + b, a + n - b, c + d, c + n - d) == 2;
  70.         } else {
  71.             return false;
  72.         }
  73.     } else if (tp == 2) {
  74.         if (a + b == c + d || a - b == c - d) {
  75.             return sumq(a + b, a + n - b, c + d, c + n - d) == 2;
  76.         } else {
  77.             return false;
  78.         }
  79.     } else if (tp == 3) {
  80.         int dx = a - c, dy = b - d;
  81.         return dx * dx + dy * dy == 5;
  82.     } else {
  83.         assert(tp == 4);
  84.         if (a == c || b == d) {
  85.             return sump(a, b, c, d) == 2;
  86.         } else {
  87.             return false;
  88.         }
  89.     }
  90. }
  91.  
  92. pair<int, int> check() {
  93.     prepare();
  94.     int ww = 0, bb = 0;
  95.     for (int i = 0; i < n; ++i) {
  96.         for (int j = 0; j < n; ++j) {
  97.             bool f = false;
  98.             for (int a = 0; a < n; ++a) {
  99.                 for (int b = 0; b < n; ++b) {
  100.                     f |= col[a][b] * col[i][j] == -1 && hit(a, b, i, j);
  101.                 }
  102.             }
  103.             if (col[i][j] == +1) {
  104.                 ww += f;
  105.             } else if (col[i][j] == -1) {
  106.                 bb += f;
  107.             }
  108.         }
  109.     }
  110.     return {ww, bb};
  111. }
  112.  
  113. signed main() {
  114. #ifdef LC
  115.     assert(freopen("input.txt", "r", stdin));
  116. #endif
  117.     ios::sync_with_stdio(0);
  118.     cin.tie(0);
  119.  
  120. /*
  121.     for (int i = 0; i < n; ++i) {
  122.         for (int j = 0; j < n; ++j) {
  123.             char c;
  124.             cin >> c;
  125.             if (c == '.') {
  126.                 continue;
  127.             }
  128.             if (isupper(c)) {
  129.                 col[i][j] = +1;
  130.                 c = tolower(c);
  131.             } else {
  132.                 col[i][j] = -1;
  133.             }
  134.             if (c == 'q') {
  135.                 p[i][j] = 1;
  136.             } else if (c == 'b') {
  137.                 p[i][j] = 2;
  138.             } else if (c == 'k') {
  139.                 p[i][j] = 3;
  140.             } else {
  141.                 assert(c == 'r');
  142.                 p[i][j] = 4;
  143.             }
  144.         }
  145.     }
  146. */
  147.     mt19937 rnd(chrono::system_clock::now().time_since_epoch().count());
  148.     set<pair<int, int>> was;
  149.     while (1) {
  150.         int per = rnd() % 101;
  151.         for (int i = 0; i < n; ++i) {
  152.             for (int j = 0; j < n; ++j) {
  153.                 if ((int)(rnd() % 100) < per) {
  154.                     col[i][j] = 0;
  155.                     p[i][j] = 0;
  156.                     continue;
  157.                 }
  158.                 col[i][j] = rnd() % 2 ? -1 : +1;
  159.                 p[i][j] = 1 + rnd() % 4;
  160.             }
  161.         }
  162.         auto e = check();
  163.         if (e.x > 50 || e.y > 50 || e.x > e.y) {
  164.             continue;
  165.         }
  166.         if (!was.count(e)) {
  167.             was.insert(e);
  168.             cout << (int)was.size() << "\t\t" << e.x << " " << e.y << endl;
  169.         }
  170.     }
  171.     return 0;
  172. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement