zoukankan      html  css  js  c++  java
  • 【题解】SCOI2007组队

      恩……为什么大家都这么执着于 (O(n^{2})) 的复杂度捏?如果接受 (O(n^{2} + nV)) 的复杂度,那这题可不是道**题吗( • ̀ω•́ )✧

      首先把所有的人按照身高排个序,然后我们就可以枚举一个人作为身高的最小值。此时,原式

    (A * H + B * V - C <= A * minh + B * minv) 

    我们可以把常量固定一下:

    (S_{x} = A * H_{x} - C - A * minh)

    (S_{x} + B * V_{x} <= B * minv)

    移项得到 (V_{x} - minv <= frac{-S_{x}}{B})

    不过仅仅满足这一个条件还不够,还有一个限制条件为

    (V_{x} >= minv)

    整理一下,把 minv 作为变量

     ( frac{-S_{x}}{B} + V_{x} <= minv <= V_{x})

     这样我们在 v 的取值范围上差分一下,取最值即可。

      以及虽然复杂度略高,但是鉴于优秀的常数 & 算法内容的操作简单,跑起来很快 :洛谷rank1~

    #include <bits/stdc++.h>
    using namespace std;
    #define maxn 1000000
    int n, A, B, C, mx, ans, a[maxn]; 
    
    int read()
    {
        int x = 0, k = 1;
        char c; c = getchar();
        while(c < '0' || c > '9') { if(c == '-') k = -1; c = getchar(); }
        while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
        return x * k;
    }
    
    struct node
    {
        int v, h;
        friend bool operator <(const node& a, const node& b)
        { return a.h < b.h; }
    }P[maxn];
    
    void Work(int x)
    {
        int H = P[x].h, T = H * A;
        for(int i = x; i <= n; i ++) 
        {
            int l = max(0, P[i].v - (T - A * P[i].h + C) / B);
            int r = P[i].v;
            if(l > r) continue;
            a[l] ++, a[r + 1] --;
        }
        
        for(int i = 0, tem = 0; i <= mx; i ++) 
        {
            a[i] += tem; tem = a[i];
            ans = max(ans, a[i]); a[i] = 0;
        }
    }
    
    int main()
    {
        n = read(); A = read(), B = read(), C = read();
        for(int i = 1; i <= n; i ++) 
        {
            P[i].h = read(), P[i].v = read();
            mx = max(mx, P[i].v);
        }
        sort(P + 1, P + 1 + n);
        for(int i = n; i >= 1; i --) Work(i);
        printf("%d
    ", ans);
        return 0;
    }
  • 相关阅读:
    @babel/preset-env 解决Promise被Babel编译成regenerator 运行时错误问题
    Blob ArrayBuffer 和 BinaryString StringView
    TypeScript 的尴尬:模块不如wepback完善
    Node.js(1) http和https模块发送HTTP(S)请求
    axios
    Nest.js 再探 解析HTTP请求
    红楼梦题词
    倾斜摄影
    重新认识TypeScript
    TypeScript 家族
  • 原文地址:https://www.cnblogs.com/twilight-sx/p/9908713.html
Copyright © 2011-2022 走看看