zoukankan      html  css  js  c++  java
  • bzoj3203

    凸包+三分

    想做这道题很久了

    暴力的想法就是枚举,但是这样t了

    然后发现列出来的式子满足三分

    那么整数三分最大值

    维护凸包的时候想了很长时间,觉得用斜率判很反人类

    叉积是个好东西

    #include<bits/stdc++.h>
    using namespace std;
    const int N = 1e5 + 5;
    struct data {
        double x, y;
        data() {}
        data(double _, double __) : x(_), y(__) {}
        friend data operator - (const data &a, const data &b) {
            return data(a.x - b.x, a.y - b.y);
        }
        friend double operator * (const data &a, const data &b) {
            return a.x * b.y - a.y * b.x;
        }
    } st[N];
    int n, top;
    double d, Ans, sum;
    double cal(const data &a, const data &b) {
        return (a.y - b.y) / (a.x - b.x);
    }
    int main()
    {
        scanf("%d%lf", &n, &d);
        for(int i = 1; i <= n; ++i)
        {
            double x, y, ans = 0;
            data t;
            scanf("%lf%lf", &x, &y);
            t.x = (double)i * d;
            t.y = sum;
            while(top > 1 && (t - st[top]) * (st[top] - st[top - 1]) >= 0) --top;
            st[++top] = t;
            sum += x;
            t.y += x;
            t.x += y;
            int l = 1, r = top;
            while(r - l >= 3) 
            {
                int L = (l * 2 + r) / 3, R = (l + 2 * r) / 3;
                if(cal(st[L], t) > cal(t, st[R])) r = R;
                else l = L;
            }
            for(int j = l; j <= r; ++j) ans = max(ans, cal(t, st[j]));
            Ans += ans;
        }
        printf("%.0f
    ", Ans);
        return 0;
    }
    View Code

    cf上紫了!

  • 相关阅读:
    kill tomcat with netstat
    windows cmd命令显示UTF8设置
    rtx没有振动功能
    手动加载rvm
    RESTful Java client with Apache HttpClient
    Set Up Git on windows also use github
    lcs.py 最长公共子串算法
    如何:对代理使用 IP 切换
    这个博客站点不错
    a case study
  • 原文地址:https://www.cnblogs.com/19992147orz/p/8127443.html
Copyright © 2011-2022 走看看