凸包 Codeforces605C Freelancer's Dreams

传送门:点击打开链接

题意:有n份工作,第i份工作做1个单位时间获得ai经验和bi钱,现在要凑齐p点经验和q钱,至少要工作多久,工作的时间可以为小数

思路:仔细想想总觉得哪里不对劲,是不是感觉好像只需要1份工作或者2份工作的组合就能形成最优的?

事实就是这样的,想达到最优最多只需要选择2份工作就行了,那么问题就是怎么枚举出这2份工作。

现在我们考虑单位时间内能完成的内容

我们假设向量V1(a1,b1),V2(a2,b2)....Vn(an,bn),现在要求这n个向量线性组合,且每个向量前面的系数之和<=1

我们把这些向量的约束画到草稿纸上,发现能达到的地方恰好形成了一个凸包!!

另外,因为我们并不是要求向量线性组合后要恰好等于 (p,q),而是应该在(p,q)的右上方,所以我们其实可以在凸包上处理一下,把凸包向左向下扩展到x轴和y轴,这样形成的一个凸多边形,然后再枚举每一条边相邻的两个向量组合而成最少需要多少时间能达到要求就行了。

然后就是,可能只做1份工作是最优的,那么可以直接单独考虑

#include<map>
#include<set>
#include<cmath>
#include<ctime>
#include<stack>
#include<queue>
#include<cstdio>
#include<cctype>
#include<string>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
#define fuck(x) cout<<"["<<x<<"]"
#define FIN freopen("input.txt","r",stdin)
#define FOUT freopen("output.txt","w+",stdout)
using namespace std;
typedef long long LL;

const int MX = 1e5 + 10;
const int INF = 1e6;
const double eps = 1e-9;

struct Point {
    double x, y;
    bool operator<(const Point&b) const {
        if(x == b.x) return y < b.y;
        return x < b.x;
    }
    Point() {}
    Point(double _x, double _y) {
        x = _x; y = _y;
    }
} P[MX], R[MX];

double cross(Point a, Point b, Point c) {
    return ((b.x - a.x) * (c.y - a.y) - (c.x - a.x) * (b.y - a.y));
}

int convex(int n) {
    int m = 0, k;
    sort(P, P + n);
    for(int i = 0; i < n; i++) {
        while(m > 1 && cross(R[m - 1], P[i], R[m - 2]) <= eps) m--;
        R[m++] = P[i];
    }

    k = m;
    for(int i = n - 2; i >= 0; i--) {
        while(m > k && cross(R[m - 1], P[i], R[m - 2]) <= eps) m--;
        R[m++] = P[i];
    }
    if(n > 1) m--;
    return m;
}

int n, rear;
Point p;

double solve() {
    double ret = INF;
    for(int i = 0; i < n + 3; i++) {
        if(fabs(P[i].x) > eps && fabs(P[i].y) > eps){
            ret = min(ret, max(p.x / P[i].x, p.y / P[i].y));
        }
    }
    for(int i = 1; i < rear - 1; i++) {
        double a = R[i].x, b = R[i].y, c = R[i + 1].x, d = R[i + 1].y;
        double x = (a * p.y - b * p.x) / (a * d - b * c), y = (c * p.y - d * p.x) / (c * b - a * d);
        if(x < -eps || y < -eps) continue;
        ret = min(ret, x + y);
    }
    return ret;
}

int main() {
    //FIN;
    while(~scanf("%d%lf%lf", &n, &p.x, &p.y)) {
        double max1 = 0, max2 = 0;
        for(int i = 0; i < n; i++) {
            scanf("%lf%lf", &P[i].x, &P[i].y);
            max1 = max(max1, P[i].x);
            max2 = max(max2, P[i].y);
        }
        P[n] = Point(max1, 0);
        P[n + 1] = Point(0, max2);
        P[n + 2] = Point(0, 0);
        rear = convex(n + 3);
        printf("%.15f\n", (double)solve());
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值