tnnd,给我 70pts 是吧!!1
查看原帖
tnnd,给我 70pts 是吧!!1
627636
封禁用户楼主2023/1/9 17:38

省流:大模拟求调。

#include <iostream>
#include <algorithm>
using namespace std;
char a[400005]; int n, f[400005], seele[400005], sing[400005]; bool qwq[400005];
int convert(int x, int y) {return x * n + y;}
int find(int x) {return f[x] == x ? x : f[x] = find(f[x]);}
void merge(int x, int y) {if (find(x) != find(y)) seele[find(y)] += seele[find(x)]; f[find(x)] = find(y);} // x -> y
void merge2(int x, int y) { // x -> y
if (a[x] == '.' || a[y] == '.') return;
seele[find(x)]--; seele[find(y)]--;
if (a[x] == a[y]) merge(x, y);
}
int main() {ios::sync_with_stdio(0);
int bx=1, by=1, wx=1, wy=1; bool side=false; cin >> n;
// false = B, true = W
for (int i=1; i<=n; i++) for (int j=1; j<=n; j++) cin >> a[convert(i, j)];
for (int i=1; i<=n; i++) for (int j=1; j<=n; j++) {f[convert(i, j)] = convert(i, j); seele[convert(i, j)] = 4 - (i == 1) - (i == n) - (j == 1) - (j == n);}
for (int i=1; i<=n; i++) for (int j=1; j<=n; j++) {if (i > 1) merge2(convert(i, j), convert(i-1, j)); if (j > 1) merge2(convert(i, j), convert(i, j-1));}
while (side ? wy <= n : by <= n) {

//for (int TLE=1; TLE<=n; TLE++) {for (int WA=1; WA<=n; WA++) cout << a[find(convert(TLE, WA))] << ' '; cout << endl;} cout << endl;
if (side) {// Wtp
if (a[convert(wx, wy)] != '.') {wx + 1 <= n ? wx++ : (wy += (wx = 1)); continue;}
if (wx > 1 && a[convert(wx-1, wy)] == 'X') seele[find(convert(wx-1, wy))]--;
if (wx < n && a[convert(wx+1, wy)] == 'X') seele[find(convert(wx+1, wy))]--;
if (wy > 1 && a[convert(wx, wy-1)] == 'X') seele[find(convert(wx, wy-1))]--;
if (wy < n && a[convert(wx, wy+1)] == 'X') seele[find(convert(wx, wy+1))]--;
if (wx > 1 && a[convert(wx-1, wy)] == 'X' && !seele[find(convert(wx-1, wy))] ||
    wx < n && a[convert(wx+1, wy)] == 'X' && !seele[find(convert(wx+1, wy))] ||
    wy > 1 && a[convert(wx, wy-1)] == 'X' && !seele[find(convert(wx, wy-1))] ||
    wy < n && a[convert(wx, wy+1)] == 'X' && !seele[find(convert(wx, wy+1))]) {
if (wx > 1 && a[convert(wx-1, wy)] == 'X') seele[find(convert(wx-1, wy))]++;
if (wx < n && a[convert(wx+1, wy)] == 'X') seele[find(convert(wx+1, wy))]++;
if (wy > 1 && a[convert(wx, wy-1)] == 'X') seele[find(convert(wx, wy-1))]++;
if (wy < n && a[convert(wx, wy+1)] == 'X') seele[find(convert(wx, wy+1))]++;
wx + 1 <= n ? wx++ : (wy += (wx = 1)); continue;
}
if (wx > 1 && a[convert(wx-1, wy)] == 'X') seele[find(convert(wx-1, wy))]++;
if (wx < n && a[convert(wx+1, wy)] == 'X') seele[find(convert(wx+1, wy))]++;
if (wy > 1 && a[convert(wx, wy-1)] == 'X') seele[find(convert(wx, wy-1))]++;
if (wy < n && a[convert(wx, wy+1)] == 'X') seele[find(convert(wx, wy+1))]++;
int test = seele[convert(wx, wy)];
if (wx > 1 && a[convert(wx-1, wy)] == 'O') {qwq[find(convert(wx-1, wy))] = true; test += seele[find(convert(wx-1, wy))] - 1;} 
if (wx < n && a[convert(wx+1, wy)] == 'O' && !qwq[find(convert(wx+1, wy))]) {test += seele[find(convert(wx+1, wy))] - 1; qwq[find(convert(wx+1, wy))] = true;}
if (wy > 1 && a[convert(wx, wy-1)] == 'O' && !qwq[find(convert(wx, wy-1))]) {test += seele[find(convert(wx, wy-1))] - 1; qwq[find(convert(wx, wy-1))] = true;}
if (wy < n && a[convert(wx, wy+1)] == 'O' && !qwq[find(convert(wx, wy+1))]) {test += seele[find(convert(wx, wy+1))] - 1; qwq[find(convert(wx, wy+1))] = true;}
if (wx > 1 && a[convert(wx-1, wy)] != '.') test--;
if (wx < n && a[convert(wx+1, wy)] != '.') test--;
if (wy > 1 && a[convert(wx, wy-1)] != '.') test--;
if (wy < n && a[convert(wx, wy+1)] != '.') test--;
wx > 1 && (qwq[find(convert(wx-1, wy))] = false); wx < n && (qwq[find(convert(wx+1, wy))] = false); 
wy > 1 && (qwq[find(convert(wx, wy-1))] = false); wy < n && (qwq[find(convert(wx, wy+1))] = false);
if (!test) {wx + 1 <= n ? wx++ : (wy += (wx = 1)); continue;}
a[convert(wx, wy)] = 'O';
if (wx > 1) merge2(convert(wx, wy), convert(wx-1, wy)); if (wx < n) merge2(convert(wx, wy), convert(wx+1, wy));
if (wy > 1) merge2(convert(wx, wy), convert(wx, wy-1)); if (wy < n) merge2(convert(wx, wy), convert(wx, wy+1));
cout << wx << ' ' << wy << endl; side ^= 1; wx + 1 <= n ? wx++ : (wy += (wx = 1));

} else {

if (a[convert(bx, by)] != '.') {bx + 1 <= n ? bx++ : (by += (bx = 1)); continue;}
if (bx > 1 && a[convert(bx-1, by)] == 'O') seele[find(convert(bx-1, by))]--;
if (bx < n && a[convert(bx+1, by)] == 'O') seele[find(convert(bx+1, by))]--;
if (by > 1 && a[convert(bx, by-1)] == 'O') seele[find(convert(bx, by-1))]--;
if (by < n && a[convert(bx, by+1)] == 'O') seele[find(convert(bx, by+1))]--;
if (bx > 1 && a[convert(bx-1, by)] == 'O' && !seele[find(convert(bx-1, by))] ||
    bx < n && a[convert(bx+1, by)] == 'O' && !seele[find(convert(bx+1, by))] ||
    by > 1 && a[convert(bx, by-1)] == 'O' && !seele[find(convert(bx, by-1))] ||
    by < n && a[convert(bx, by+1)] == 'O' && !seele[find(convert(bx, by+1))]) {
if (bx > 1 && a[convert(bx-1, by)] == 'O') seele[find(convert(bx-1, by))]++;
if (bx < n && a[convert(bx+1, by)] == 'O') seele[find(convert(bx+1, by))]++;
if (by > 1 && a[convert(bx, by-1)] == 'O') seele[find(convert(bx, by-1))]++;
if (by < n && a[convert(bx, by+1)] == 'O') seele[find(convert(bx, by+1))]++;
bx + 1 <= n ? bx++ : (by += (bx = 1)); continue;
}
if (bx > 1 && a[convert(bx-1, by)] == 'O') seele[find(convert(bx-1, by))]++;
if (bx < n && a[convert(bx+1, by)] == 'O') seele[find(convert(bx+1, by))]++;
if (by > 1 && a[convert(bx, by-1)] == 'O') seele[find(convert(bx, by-1))]++;
if (by < n && a[convert(bx, by+1)] == 'O') seele[find(convert(bx, by+1))]++;
int test = seele[convert(bx, by)];
if (bx > 1 && a[convert(bx-1, by)] == 'X') {qwq[find(convert(bx-1, by))] = true; test += seele[find(convert(bx-1, by))] - 1;} 
if (bx < n && a[convert(bx+1, by)] == 'X' && !qwq[find(convert(bx+1, by))]) {test += seele[find(convert(bx+1, by))] - 1; qwq[find(convert(bx+1, by))] = true;}
if (by > 1 && a[convert(bx, by-1)] == 'X' && !qwq[find(convert(bx, by-1))]) {test += seele[find(convert(bx, by-1))] - 1; qwq[find(convert(bx, by-1))] = true;}
if (by < n && a[convert(bx, by+1)] == 'X' && !qwq[find(convert(bx, by+1))]) {test += seele[find(convert(bx, by+1))] - 1; qwq[find(convert(bx, by+1))] = true;}
if (bx > 1 && a[convert(bx-1, by)] != '.') test--;
if (bx < n && a[convert(bx+1, by)] != '.') test--;
if (by > 1 && a[convert(bx, by-1)] != '.') test--;
if (by < n && a[convert(bx, by+1)] != '.') test--;
bx > 1 && (qwq[find(convert(bx-1, by))] = false); bx < n && (qwq[find(convert(bx+1, by))] = false); 
by > 1 && (qwq[find(convert(bx, by-1))] = false); by < n && (qwq[find(convert(bx, by+1))] = false);
if (!test) {bx + 1 <= n ? bx++ : (by += (bx = 1)); continue;}
a[convert(bx, by)] = 'X';
if (bx > 1) merge2(convert(bx, by), convert(bx-1, by)); if (bx < n) merge2(convert(bx, by), convert(bx+1, by));
if (by > 1) merge2(convert(bx, by), convert(bx, by-1)); if (by < n) merge2(convert(bx, by), convert(bx, by+1));
cout << bx << ' ' << by << endl; side ^= 1; bx + 1 <= n ? bx++ : (by += (bx = 1));
}
}
cout << -1 << ' ' << -1;
}

写了很多毫无意义的行,希望能看得过去。

问过大模拟之神了。

2023/1/9 17:38
加载中...