您的位置:首页 > 其它

[BZOJ]3203 [SDOI2013] 保护出题人 三分

2017-12-05 22:00 363 查看

3203: [Sdoi2013]保护出题人

Time Limit: 3 Sec  Memory Limit: 128 MB
Submit: 885  Solved: 440

[Submit][Status][Discuss]

Description



Input

第一行两个空格隔开的正整数n和d,分别表示关数和相邻僵尸间的距离。接下来n行每行两个空格隔开的正整数,第i + 1行为Ai和 Xi,分别表示相比上一关在僵尸队列排头增加血量为Ai 点的僵尸,排头僵尸从距离房子Xi米处开始接近。 

Output

一个数,n关植物攻击力的最小总和 ,保留到整数。

Sample Input

5 2

3 3

1 1

10 8

4 8

2 3

Sample Output

7

HINT

第一关:距离房子3米处有一只血量3点的僵尸,植物最小攻击力为1.00000; 第二关:距离房子1米处有一只血量1点的僵尸、3米处有血量3点的僵尸,植物最小攻击力为1.33333; 第三关:距离房子8米处有一只血量10点的僵尸、10米处有血量1点的僵尸、12米处有血量3点的僵尸,植物最小攻击力为1.25000; 第四关:距离房子8米处有一只血量4点的僵尸、10米处有血量10点的僵尸、12米处有血量1点的僵尸、14米处有血量3点的僵尸,植物最小攻击力为1.40000;
第五关:距离房子3米处有一只血量2点的僵尸、5米处有血量4点的僵尸、7米处有 血量10点的僵尸、9米处有血量1点的僵尸、11米处有血量3点的僵尸,植物最小攻击力 为2.28571。 植物攻击力的最小总和为7.26905。

对于100%的数据, 1≤n≤10^5,1≤d≤10^12,1≤x≤ 10^12,1≤a≤10^12

Source



[Submit][Status][Discuss]

HOME Back

  一开始看错题了以为血量是递增的... 想了个二分做法看样例解释发现不对... 对于第n关, 只需要保证每个僵尸都不会吃到植物. 就是求max((sum[i] - sum[j - 1]) /x[i] + (i - j) * d. 然后拆开就会发现是两点之间的斜率. 那么要求最大斜率肯定就是维护下凸壳.
到定点距离会发现是单峰函数, 三分即可.

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int n, top;
double sum[maxn], xx[maxn], d;
double tmp, ans;
inline const int read() {
register int x = 0;
register char ch = getchar();
while (ch < '0' || ch > '9') ch = getchar();
while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
return x;
}
struct Point{
double x, y;
Point() {}
Point(double x, double y) : x(x), y(y) {}
inline friend Point operator - (const Point &r, const Point &s) {
return Point(r.x - s.x, r.y - s.y);
}
}pts[maxn], cvx[maxn], q;
typedef Point Vector;
inline double cross(const Vector &r, const Vector &s) {
return r.x * s.y - r.y * s.x;
}
inline bool onleft(const Point &A, const Point &B, const Point &C) {
return cross(C - A, B - A) >= 0;
}
inline double slopego(const Point &A, const Point &B) {
return (B.y - A.y) / (B.x - A.x);
}
inline double check() {
tmp = 0;
int lf = 1, rg = top, lmid, rmid;
while (rg >= lf + 3) {
lmid = lf + (rg - lf) / 3;
rmid = rg - (rg - lf) / 3;
if (slopego(cvx[rmid], q) > slopego(cvx[lmid], q)) lf = lmid;
else rg = rmid;
}
for (int i = lf; i <= rg; ++ i) tmp = max(slopego(cvx[i], q), tmp);
return tmp;
}
int main() {
n = read(), d = read();
for (register int i = 1; i <= n; ++ i) {
sum[i] = read(), xx[i] = read();
sum[i] += sum[i - 1];
pts[i].x = i * d, pts[i].y = sum[i - 1];
}
for (register int i = 1; i <= n; ++ i) {
while(top > 1 && onleft(cvx[top - 1], cvx[top], pts[i])) top --;
cvx[++ top] = pts[i];
q.x = xx[i] + i * d, q.y = sum[i];
ans += check();
}
printf("%.0lf\n", ans);
}


 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: