Luogu 4951 [USACO 2001 OPEN]地震
水个博客玩。
$01$分数规划。
题目要求$\frac{F - \sum_{i = 1}^{n}C_i}{T_i}$最大,设$\frac{F - \sum_{i}C_i}{T_i} \geq e$,移项一下可以得到$F - \sum_{i }(e * T_i + C_i) \geq 0$。
那么在外层二分一个$e$,然后把所有边的权值设成$e * T_i + C_i$做最小生成树,假设这样子生成树的权值为$res$,如果$F - res > 0$ 那么说明答案还可以更大,否则更小。
时间复杂度$O(mlogmlogn(MaxInt))$。
Code:
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef double db; const int N = ;
const int M = ;
const db eps = 1e-;
const db inf = 1e10; int n, m, ufs[N];
ll cur; struct Pathway {
int u, v;
ll c, t;
db val; friend bool operator < (const Pathway &x, const Pathway &y) {
return x.val < y.val;
} } pat[M]; template <typename T>
inline void read(T &X) {
X = ; char ch = ; T op = ;
for(; ch > '' || ch < ''; ch = getchar())
if(ch == '-') op = -;
for(; ch >= '' && ch <= ''; ch = getchar())
X = (X << ) + (X << ) + ch - ;
X *= op;
} int find(int x) {
return x == ufs[x] ? x : ufs[x] = find(ufs[x]);
} inline bool chk(db mid) {
for(int i = ; i <= m; i++)
pat[i].val = mid * pat[i].t + 1.0 * pat[i].c; sort(pat + , pat + + m);
for(int i = ; i <= n; i++) ufs[i] = i;
int cnt = ; db res = ;
for(int i = ; i <= m; i++) {
int u = find(pat[i].u), v = find(pat[i].v);
if(u == v) continue;
ufs[u] = v;
++cnt;
res += pat[i].val;
if(cnt >= n - ) break;
} return (1.0 * cur - res) > ;
} int main() {
read(n), read(m), read(cur);
for(int i = ; i <= m; i++)
read(pat[i].u), read(pat[i].v), read(pat[i].c), read(pat[i].t); db ln = 0.0, rn = inf, mid, res = 0.0;
for(; ln + eps <= rn; ) {
mid = (ln + rn) * 0.5;
if(chk(mid)) ln = mid, res = mid;
else rn = mid;
} printf("%.4f\n", res);
return ;
}
Luogu 4951 [USACO 2001 OPEN]地震的更多相关文章
- [ USACO 2001 OPEN ] 地震
\(\\\) Description 给出一张 \(n\) 个点 \(m\) 条边的无向图,现在要建一棵生成树. 每条边都有消耗的时间 \(t_i\),也有建造的代价 \(w_i\) . 最后总金给 ...
- USACO 2001 OPEN
第1题 绿组. 奶牛接力赛[relay] 题目描述 农夫约翰已经为一次赛跑选出了K(2≤K≤40)头牛组成了一支接力队.赛跑在农夫约翰所拥有的农场上进行,农场的编号为1到Ⅳf4≤Ⅳ< 800), ...
- Cow Relays 【优先队列优化的BFS】USACO 2001 Open
Cow Relays Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Tota ...
- USACO 2001 OPEN earthquake /// 最优比例生成树
题目大意: https://www.cnblogs.com/forever97/p/3603572.html 讲解:https://www.jianshu.com/p/d40a740a527e 题解: ...
- [USACO]地震 (二分答案+最优比率生成树详解)
题面:[USACO 2001 OPEN]地震 题目描述: 一场地震把约翰家的牧场摧毁了, 坚强的约翰决心重建家园. 约翰已经重建了N个牧场,现在他希望能修建一些道路把它们连接起来.研究地形之后,约翰发 ...
- POJ 1703 Find them, Catch them(并查集高级应用)
手动博客搬家:本文发表于20170805 21:25:49, 原地址https://blog.csdn.net/suncongbo/article/details/76735893 URL: http ...
- usaco 地震 && 奶牛观光
Usaco 地震: Description 一场地震把约翰家的牧场摧毁了,坚强的约翰决心重建家园.约翰已经重建了N个牧场, 现在他希望能修建一些道路把它们连接起来.研究地形之后,约翰发现可供修建的道路 ...
- 洛谷4951 地震 bzoj1816扑克牌 洛谷3199最小圈 / 01分数规划
洛谷4951 地震 #include<iostream> #include<cstdio> #include<algorithm> #define go(i,a,b ...
- Luogu USACO Training 刷水记录
开个坑记录一下刷USACO的Training的记录 可能会随时弃坑 只有代码和做法简述 可能没有做法简述 [USACO1.1]你的飞碟在这儿Your Ride Is He… 模拟,细节已忘 #incl ...
随机推荐
- MyEclipse2014快速配置Spring & Spring Testing, Spring AOP简单使用
1.新建项目 2.右击项目,如图,利用myeclipse自动导入spring 3.在弹出的对话框中一直next到最后,在最后的页面中勾选Spring Testing,完成. 4.在src下的appli ...
- bisect模块用于插入
参考链接: chttp://www.cnblogs.com/skydesign/archive/2011/09/02/2163592.html水
- 转发一篇关于django模型详解的一篇好的博客
http://blog.csdn.net/pipisorry/article/details/45725953
- 笔记:Why don't you pull up a chair and give this lifestyle a try?
Why don't you pull up a chair and give this lifestyle a try? Why don't you pull up a chair and give ...
- Linux C程序操作Mysql 调用PHP采集淘宝商品
还是继续这个项目. 在上一篇Linux下利用Shell使PHP并发采集淘宝产品中,采用shell将对PHP的调用推到后台执行,模拟多线程. 此方法有一致命缺点,只能人工预判每个程序执行时间.如果判断时 ...
- php MySQL使用rand函数随机取记录(转)
php MySQL使用rand函数随机取记录 如何在mysql中使用随机数, 如何写一个语句能一下更新几百条MYSQL数据! 需要测试MYSQL数据库,里面有一个上万条数据的数据库,如何写一个PHP文 ...
- 洛谷【P1064】金明的预算方案
浅谈\(DP\):https://www.cnblogs.com/AKMer/p/10437525.html 题目传送门:https://www.luogu.org/problemnew/show/P ...
- RK3288 dts文件中背光配置参数
backlight { // 设备名(用于匹配) compatible = "pwm-backlight"; // pwm编号 通道 频率(ns) pwms = <& ...
- Chrome 的审查元素功能有哪些奇技淫巧
学习地址: https://www.zhihu.com/question/34682699
- getpass密码隐藏
使用getpass模块对输入的字符进行隐藏输入 #-*- coding:utf-8 -*- __author__ = "MuT6 Sch01aR" import getpass u ...