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 ...
随机推荐
- 在vue项目中正确的引入jquery和bootstrap
<script>标签引入jquery在vue脚手架里并不适用,需要利用webpack引入jquery 一.第一种方法 1:因为已经安装了vue脚手架,所以需要在webpack中全局引入jq ...
- jfrog artifactory jenkins pipeline 集成
1. 预备环境 artifactory ( 开源版本 ) maven jenkins jenkins artifactory plugin (在插件管理安装即可) 2. 配置artifactory ...
- STM32从boot跳转到app失败
现象:在每次boot执行完跳转到APP时,都会跑飞 原因:在boot中使用到了USART和TIM,boot执行完没有关闭总中断 方法:在boot执行完跳转之前关闭中断,__disable_irq() ...
- JMeter接口学习笔记2017
协议学习地址:http://www.cnblogs.com/TankXiao/archive/2012/02/13/2342672.html 本篇学习笔记来自于慕课网上学习JMeter的学习笔记 学习 ...
- git超速掌握之一(基本使用)
前言: 无论你是运维.开发还是IT爱好者,都会听说github了吧?动不动哪位大神就说在github上有什么什么项目,我的github地址是xxxxx,甚至有自己个github在找新工作时都能给自己加 ...
- MonGoDB问题笔记
1. 最近出了一个问题,就是按日期查查不出来数据,经过折腾后发现,mongodb中的存储数据的日期格式与查询时使用的日期格式不匹配,导致查询出不来 //{"$and":[{ &qu ...
- 显示等待 之 text_to_be_present_in_element 判断元素是否有xx 文本信息 用法
- thinkphp中的_initialize方法
子类的_initialize方法自动调用父类的_initialize方法.而php的构造函数construct,如果要调用父类的方法,必须在子类构造函数显示调用parent::__construct( ...
- MFC调试的几个技巧
TCHAR pStr[] = _T("this is a test!"); void* p = (void*)pStr; TRACE(_T("pStr is %s\n&q ...
- python's twenty_fourth day for me 内置方法
str repr: 1,当需要使用__str__的场景时找不到__str__就找__repr__ 2,当需要使用__repr__的场景时找不到__repr__的时候就找父类的repr. 3,双下re ...