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\n", Ans); return 0; }
cf上紫了!