Codeforces Round #335 (Div. 1)--C. Freelancer's Dreams 线性规划对偶问题+三分
题意:p, q,都是整数.
sigma(Ai * ki)>= p,
sigma(Bi * ki) >= q;
ans = sigma(ki)。输出ans的最小值
约束条件2个,但是变量k有100000个,所以可以利用对偶性转化为求解
ans = p * y1 + q * y2
约束条件为:
Ai * y1 + Bi * y2 <= 1 其中i为0~n-1
也就是n个约束条件。 后面三分搞搞就好了
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + ;
double A[maxn], B[maxn], p, q;
int n;
double check(double x){
double y = 1e20;
for (int i = ; i < n; i++){
y = min(y, (-A[i]*x)/B[i]);
}
return p * x + y * q;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
while (~scanf("%d%lf%lf", &n, &p, &q)){
for (int i = ; i < n; i++){
scanf("%lf%lf", A+i, B+i);
}
double l = , r = 1.0/(*max_element(A, A+n));
for (int i = ; i < ; i++){
double ml = (l + l + r) / ;
double mr = (r + r + l) / ;
if (check(ml) > check(mr)){
r = mr;
}else{
l = ml;
}
}
printf("%.20f\n", check((l+l)/));
}
return ;
}
Codeforces Round #335 (Div. 1)--C. Freelancer's Dreams 线性规划对偶问题+三分的更多相关文章
- Codeforces Round #335 (Div. 1) C. Freelancer's Dreams 计算几何
C. Freelancer's Dreams Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/contes ...
- Codeforces Round #335 (Div. 2) B. Testing Robots 水题
B. Testing Robots Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/contest/606 ...
- Codeforces Round #335 (Div. 2) D. Lazy Student 构造
D. Lazy Student Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/606/probl ...
- Codeforces Round #335 (Div. 2) C. Sorting Railway Cars 动态规划
C. Sorting Railway Cars Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/conte ...
- Codeforces Round #335 (Div. 2) A. Magic Spheres 水题
A. Magic Spheres Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/contest/606/ ...
- Codeforces Round #335 (Div. 2) D. Lazy Student 贪心+构造
题目链接: http://codeforces.com/contest/606/problem/D D. Lazy Student time limit per test2 secondsmemory ...
- Codeforces Round #335 (Div. 2)
水 A - Magic Spheres 这题也卡了很久很久,关键是“至少”,所以只要判断多出来的是否比需要的多就行了. #include <bits/stdc++.h> using nam ...
- Codeforces Round #335 (Div. 2) A. Magic Spheres 模拟
A. Magic Spheres Carl is a beginner magician. He has a blue, b violet and c orange magic spheres. ...
- Codeforces Round #335 (Div. 2) D. Lazy Student 贪心
D. Lazy Student Student Vladislav came to his programming exam completely unprepared as usual. He ...
随机推荐
- C# Activator.CreateInstance()
C#在类工厂中动态创建类的实例,所使用的方法为: 1. Activator.CreateInstance (Type) 2. Activator.CreateInstance (Type, Objec ...
- jquery 操作 checkbox
对checkbox的其他几个操作 1. 全选2. 取消全选3. 选中所有奇数4. 反选5. 获得选中的所有值 js代码 $("document").ready(function() ...
- Deep Learning 学习随记(四)自学习和非监督特征学习
接着看讲义,接下来这章应该是Self-Taught Learning and Unsupervised Feature Learning. 含义: 从字面上不难理解其意思.这里的self-taught ...
- Xaml中的资源(1 样式)
<Window x:Class="MyResoures.MainWindow" xmlns="http://schemas.microsoft.com/winfx/ ...
- java_设计模式_外观模式_Facade Pattern(2016-08-09)
外观模式/门面模式 1.概念 为子系统中的一组接口提供一个统一接口.Facade模式定义了一个高层接口,这个接口使得这子系统更容易使用. 2.UML 由于外观模式的结构图过于抽象,因此把它稍稍具体点. ...
- shell调用shell
在默认条件下,执行shell文件会出现permission denied报错,一般是没有可执行权限.用chmod修改权限 chomd 777 score.sh //把所有权限给aa文件 777代表 ...
- H5相关
对于容器元素,尤其在做移动端产品时候,我们很自然会让其居中定位: .container { position: absolute; left: %; top: %; transform: transl ...
- ffmepg命令行参数
ffmpeg使用 有些选项在每个流中都必须指定,例如比特率bitrate或编解码codec.指定流的字符串一般都会有各参数名称和参数,如编解码"-codec:a:1 ac3"表明第 ...
- CMD下查询Mysql中文乱码的解决方法
我的MySQL是默认utf8编码的,所建数据库也是设置utf8编码,使用程序可以新增中文数据,在cmd中使用SQL语句新增数据则报类似Incorrect string value: '\xB2\xE2 ...
- js字符串 数字 的转换
js 字符串转化成数字 的 三种方法主要有 转换函数.强制类型转换.利用js变量弱类型转换. 1. 转换函数: js提供了parseInt()和parseFloat()两个转换函数.前者把值转换成整数 ...