zoukankan      html  css  js  c++  java
  • 洛谷P4704 太极剑(乱搞)

    题意

    题目链接

    Sol

    不会正解

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

    // 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;
    }
    
  • 相关阅读:
    Wiin10 深色模式 暗色 省电 经济 护眼dark mode energy saving ecol
    云主机终端现实中文
    systemctl enable与systemctl start的区别
    centos技巧
    用国内的vps登录亚马逊的ec2
    小米 redmi note 8 打开开发者选项
    javascript数组、对象和Null的typeof同为object,区分解决办法
    组件中是否可以判断slot是否有内容?
    xlsx-style 行高设置
    修改xlsx-style 源码 解决报错
  • 原文地址:https://www.cnblogs.com/zwfymqz/p/10467063.html
Copyright © 2011-2022 走看看