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 ...
随机推荐
- Chrome浏览器允许跨域请求配置
最近有个做数据标注的任务,但是标注平台是别人公司的,他们又不愿意对平台进行升级改造: 其实要改的地方也很简单,就是对页面做一些处理,做一些脚本控制. 没办法,做了个 iframe 给她嵌入到我们自己的 ...
- 如何配置visual studio 2013进行负载测试-万事开头难
声明:工作比较忙,文章写得不好,有时间再整理. 起因:最近众包平台因迁移到azure之后一直有网站慢的情况,让老板挨批了,但是测试环境一切正常,而且生产环境也没发现有卡顿和慢的情况,所以干脆来一次负载 ...
- Deep Learning 学习随记(六)Linear Decoder 线性解码
线性解码器(Linear Decoder) 前面第一章提到稀疏自编码器(http://www.cnblogs.com/bzjia-blog/p/SparseAutoencoder.html)的三层网络 ...
- 段落排版--缩进(text-indent)
中文文字中的段前习惯空两个文字的空白,这个特殊的样式可以用下面代码来实现: p{text-indent:2em;} <p>1922年的春天,一个想要成名名叫尼克卡拉威(托比?马奎尔Tobe ...
- Core Animation之CAKeyframeAnimation
在上一篇专题文章中我们学习了iOS核心动画CoreAnimation中CABasicAnimation动画的使用方法.CABasicAnimation已经可以应付一些比较简单的应用场景了,比如view ...
- 为什么我们不喜欢用富UI控件
我们对于理解一般意义的抽象关系并没有问题,但如第一部分使用Entity Framework 时说明的,事实恰好相反.我们还喜欢在交付应用程序时利用抽象关系,比如使用Azure等云服务.在这两种情况下, ...
- Oracle数据库之动态SQL
Oracle数据库之动态SQL 1. 静态SQLSQL与动态SQL Oracle编译PL/SQL程序块分为两个种:一种为前期联编(early binding),即SQL语句在程序编译期间就已经确定,大 ...
- photoshop cc 版本安装失败解决办法
好久没有碰ps,看了下在ps版本都到cc了.忍不住也想尝试最新版本,但是安装出现了很多问题,导致我花了很多时间才搞定,现在分享给大家几点经验吧. Exit Code: Please see speci ...
- MongoDB 与传统关系型数据库mysql比较
与关系型数据库相比,MongoDB的优点: 转载自 http://blog.sina.com.cn/s/blog_966e430001019s8v.html①弱一致性(最终一致),更能保证用户的访问 ...
- Delphi中停靠技术的实现
随着软件技术的不断进步,软件界面也越来越美观,操作也越来越方便.综观市面上比较专业的各种软件,我们会发现大部分都提供窗体停靠的功能,特别象工具软件,基本上都或多或少有停靠功能.自然,Delphi也支持 ...