codeforce 605BE. Freelancer's Dreams

题意:给你n个工程,做了每个工程相应增长x经验和y钱。问你最少需要多少天到达制定目标。时间可以是浮点数。

思路:杜教思路,用对偶原理很简易。个人建议还是标准解题法,凸包+线性组合。

 1 #include<iostream>
 2 #include<string>
 3 #include<algorithm>
 4 #include<cstdlib>
 5 #include<cstdio>
 6 #include<set>
 7 #include<map>
 8 #include<vector>
 9 #include<cstring>
10 #include<stack>
11 #include<cmath>
12 #include<queue>
13 #include <bits/stdc++.h>
14 using namespace std;
15 #define CL(x,v); memset(x,v,sizeof(x));
16 #define INF 0x3f3f3f3f
17 #define LL long long
18 const int SIGMA_SIZE = 26;
19 const int MAXNODE = 111000;
20 const int MAXS = 150 + 10;
21 const int maxn = 1e5+10;
22 int a[maxn], b[maxn];
23 int n, p, q;
24 
25 double f(double x)
26 {
27     double y = 1;
28     for(int i=0;i<n;i++) y = min(y, (1.0 - x*b[i]) / a[i]);
29     return y*p + x*q;
30 }
31 
32 int main()
33 {
34     cin >> n >> p >> q;
35     for(int i=0;i<n;i++) cin >> a[i] >> b[i];
36     double l=0, r = 1./ (*max_element(b, b+n));
37     for(int i=0;i<200;i++)
38     {
39         double ll = (l+l+r)/3, rr = (r + r+l)/3;
40         if(f(ll) > f(rr)) r = rr;
41         else l = ll;
42     }
43     printf("%.10f\n", f((l+r)*0.5));
44     return 0;
45 }
View Code

 

转载于:https://www.cnblogs.com/ITUPC/p/5049951.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值