Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- using ll = long long;
- #define int ll
- #define all(x) x.begin(), x.end()
- #define x first
- #define y second
- #define mp make_pair
- #define mt make_tuple
- const int N = 20;
- int n = 8;
- bool ok(int i, int j) {
- return 0 <= i && i < N && 0 <= j && j < N;
- }
- int p[N][N], q[N][N], col[N][N];
- int prefp[N][N], prefq[N][N];
- void prepare() {
- fill_n(q[0], N * N, 0);
- fill_n(prefp[0], N * N, 0);
- fill_n(prefq[0], N * N, 0);
- for (int i = 0; i < n; ++i) {
- for (int j = 0; j < n; ++j) {
- q[i + j][i + n - j] = p[i][j];
- }
- }
- for (int i = 0; i < N - 1; ++i) {
- for (int j = 0; j < N - 1; ++j) {
- prefp[i + 1][j + 1] = prefp[i + 1][j] + prefp[i][j + 1] - prefp[i][j] + (p[i][j] != 0);
- prefq[i + 1][j + 1] = prefp[i + 1][j] + prefp[i][j + 1] - prefp[i][j] + (q[i][j] != 0);
- }
- }
- }
- int sump(int a, int b, int c, int d) {
- if (a > c) {
- swap(a, c);
- }
- if (b > d) {
- swap(b, d);
- }
- ++c, ++d;
- return prefp[c][d] - prefp[a][d] - prefp[c][b] + prefp[a][b];
- }
- int sumq(int a, int b, int c, int d) {
- if (a > c) {
- swap(a, c);
- }
- if (b > d) {
- swap(b, d);
- }
- ++c, ++d;
- return prefq[c][c] - prefq[a][d] - prefq[c][b] + prefq[a][b];
- }
- bool hit(int a, int b, int c, int d) {
- int tp = p[a][b];
- if (a == c && b == d) {
- return false;
- }
- if (tp == 0) {
- return false;
- } else if (tp == 1) {
- if (a == c || b == d) {
- return sump(a, b, c, d) == 2;
- } else if (a + b == c + d || a - b == c - d) {
- return sumq(a + b, a + n - b, c + d, c + n - d) == 2;
- } else {
- return false;
- }
- } else if (tp == 2) {
- if (a + b == c + d || a - b == c - d) {
- return sumq(a + b, a + n - b, c + d, c + n - d) == 2;
- } else {
- return false;
- }
- } else if (tp == 3) {
- int dx = a - c, dy = b - d;
- return dx * dx + dy * dy == 5;
- } else {
- assert(tp == 4);
- if (a == c || b == d) {
- return sump(a, b, c, d) == 2;
- } else {
- return false;
- }
- }
- }
- pair<int, int> check() {
- prepare();
- int ww = 0, bb = 0;
- for (int i = 0; i < n; ++i) {
- for (int j = 0; j < n; ++j) {
- bool f = false;
- for (int a = 0; a < n; ++a) {
- for (int b = 0; b < n; ++b) {
- f |= col[a][b] * col[i][j] == -1 && hit(a, b, i, j);
- }
- }
- if (col[i][j] == +1) {
- ww += f;
- } else if (col[i][j] == -1) {
- bb += f;
- }
- }
- }
- return {ww, bb};
- }
- signed main() {
- #ifdef LC
- assert(freopen("input.txt", "r", stdin));
- #endif
- ios::sync_with_stdio(0);
- cin.tie(0);
- /*
- for (int i = 0; i < n; ++i) {
- for (int j = 0; j < n; ++j) {
- char c;
- cin >> c;
- if (c == '.') {
- continue;
- }
- if (isupper(c)) {
- col[i][j] = +1;
- c = tolower(c);
- } else {
- col[i][j] = -1;
- }
- if (c == 'q') {
- p[i][j] = 1;
- } else if (c == 'b') {
- p[i][j] = 2;
- } else if (c == 'k') {
- p[i][j] = 3;
- } else {
- assert(c == 'r');
- p[i][j] = 4;
- }
- }
- }
- */
- mt19937 rnd(chrono::system_clock::now().time_since_epoch().count());
- set<pair<int, int>> was;
- while (1) {
- int per = rnd() % 101;
- for (int i = 0; i < n; ++i) {
- for (int j = 0; j < n; ++j) {
- if ((int)(rnd() % 100) < per) {
- col[i][j] = 0;
- p[i][j] = 0;
- continue;
- }
- col[i][j] = rnd() % 2 ? -1 : +1;
- p[i][j] = 1 + rnd() % 4;
- }
- }
- auto e = check();
- if (e.x > 50 || e.y > 50 || e.x > e.y) {
- continue;
- }
- if (!was.count(e)) {
- was.insert(e);
- cout << (int)was.size() << "\t\t" << e.x << " " << e.y << endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement