题意

题目链接

Sol

不会正解

写了发暴力过了,貌似跑的还挺快?。。

洛谷P4704 太极剑(乱搞)-LMLPHP

// luogu-judger-enable-o2
// luogu-judger-enable-o2
#include<bits/stdc++.h>
#define MP(x, y) make_pair(x, y)
#define fi first
#define se second
#define LL long long
template <typename A, typename B> inline bool chmin(A &a, B b){if(a > b) {a = b; return 1;} return 0;}
template <typename A, typename B> inline bool chmax(A &a, B b){if(a < b) {a = b; return 1;} return 0;}
#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1<<22, stdin), p1 == p2) ? EOF : *p1++)
char buf[(1 << 22)], *p1 = buf, *p2 = buf;
using namespace std;
const int MAXN = 8e5 + 10, INF = 1e9;
const double eps = 1e-5;
inline int read() {
char c = getchar(); int x = 0, f = 1;
while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
int N, a[MAXN], b[MAXN], col[MAXN], out, x, y, gg = INF, ti[MAXN], ss, st[MAXN], top;
int solve(int l, int r) {
ss++;
int ans = 0;
for(int i = l; i <= r; i++) {
if(ti[col[i]] != ss) ti[col[i]] = ss;
else ans++, ss++;
if(ans >= out) return out;
}
return ans;
}
signed main() {
N = read();
for(int i = 1; i <= N; i++) {
a[i] = read(), b[i] = read();
if(a[i] > b[i]) swap(a[i], b[i]);
col[a[i]] = col[a[i] + 2 * N] = i;
col[b[i]] = col[b[i] + 2 * N] = i;
int tmp = min(b[i] - a[i], a[i] - b[i] + 2 * N);
if(tmp < gg) x = a[i], y = b[i], gg = tmp;
}
out = INF;
for(int i = x; i <= y; i++) st[++top] = i;
random_shuffle(st + 1, st + top + 1);
for(int i = 1; i <= top; i++) {
int k = st[i];
chmin(out, solve(k, k + 2 * N - 1));
}
cout << out / 2 +1;
return 0;
}
05-11 11:17