CF605C Freelancer's Dreams 凸包+三分

版权声明:2333 https://blog.csdn.net/liangzihao1/article/details/82459370

题目大意:
n 个工作,每个工作一个单位时间有一个经验值 a i 和金钱 b i ,问拿到 p 经验和 q 金钱的时间最小值,工作时间可以是小数。
n <= 1 e 5

分析:
一个工作可以看做是一个向量,相当于求向量和。
考虑一个单位时间的答案,就是这一堆向量加上 ( m a x a , 0 ) ( 0 , m a x b ) ( 0 , 0 ) 的凸包。
然后再求 y = ( q / p ) x 与凸包的交点即可。

代码:


 #include <bits/stdc++.h>
using namespace std;
int a[100010], b[100010];
int n, p, q;
double f(double x){
    double y = 1;
    for(int i=0;i<n;i++)y=min(y,((double)1- x*b[i])/a[i]);
    return y*p + x*q;
}

int main() {
    scanf("%d%d%d",&n,&p,&q);
    int maxx=0;
    for(int i=0;i<n;i++){scanf("%d%d",&a[i],&b[i]);maxx=max(maxx,b[i]);}
    double l=0,r=(double)1/maxx;
    int t=1000;
    while(t--){
        double l2=(2*l+r)/3,r2=(2*r+l)/3;
        if(f(l2)<=f(r2)){l=l2;continue;}r=r2;
    }
    printf("%.10f\n",f((l+r)*0.5));
    return 0;
}

猜你喜欢

转载自blog.csdn.net/liangzihao1/article/details/82459370
今日推荐