欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

洛谷P4704 太极剑(乱搞)

程序员文章站 2023-10-31 13:41:22
题意 "题目链接" Sol 不会正解 写了发暴力过了,貌似跑的还挺快?。。 cpp // luogu judger enable o2 // luogu judger enable o2 include define MP(x, y) make_pair(x, y) define fi first ......

题意

题目链接

sol

不会正解

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

洛谷P4704 太极剑(乱搞)

// 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;
}