【题解】quake
【题解】\(quake\)
题目大意
我们共有报酬\(f\)元,一条边有它的价值\(w_i\),有它的建造时间\(t_i\)。要求建一些边,生成一颗树。求最大的利润率。
数据范围
\(n\le 400\) \(m\le10000\)
\(Solution\)
实际上\(n,m\)出到\(\le 100000\)应该也是没问题的。
分数形式?考虑数学表示一下
\(\frac{f-\Sigma c_i}{\Sigma t_i}\le ans\)
\(f-\Sigma c_i\le ans\Sigma t_i\)
\(\Sigma(ans\times t_i + c_i) \le f\)
二分就完事了,然后直接克鲁斯卡尔。
#include<bits/stdc++.h>
#define RP(t,a,b) for(register int (t)=(a),edd_=(b);t<=edd_;++t)
#define DRP(t,a,b) for(register int (t)=(a),edd_=(b);t>=edd_;--t)
#define ERP(t,a) for(int t=head[a];t;t=e[t].nx)
#define pushup(x) seg[(x)]=seg[(x)<<1]+seg[(x)<<1|1]
#define midd register int mid=(l+r)>>1
#define TMP template<class ccf>
#define rgt L,R,mid,r,pos<<1|1
#define lef L,R,l,mid,pos<<1
#define all 1,n,1
using namespace std;typedef long long ll;typedef long double db;
TMP inline ccf Max(ccf a,ccf b){return a<b?b:a;}
TMP inline ccf Min(ccf a,ccf b){return a<b?a:b;}
TMP inline ccf Abs(ccf a){return a<0?-a:a;}
TMP inline ccf qr(ccf k){
char c=getchar();ccf x=0;int q=1;
while(c<48||c>57)q=c==45?-1:q,c=getchar();
while(c>=48&&c<=57)x=x*10+c-48,c=getchar();
return q==-1?-x:x;
}
//-------------template&IO---------------------
const int maxn=405;
int r[maxn];
int head[maxn];
int cnt;
int n,m;
long double F;
long double mid;
const long double EPS=1e-10;
struct S{
int fr,to;long double w,t;
inline void mk(int FR,int TO,int W,int T){fr=FR;to=TO;w=W;t=T;}
inline bool operator <(S a){
return t*mid+w<a.t*mid+a.w;
}
}data[10001];
inline void add(int fr,int to,int w,int t){
data[++cnt].mk(fr,to,w,t);
}
inline int q(int x){
register int t=x,temp,i=x;
while(r[t]!=t) t=r[t];
while(r[i]!=i){temp=r[i];r[i]=t;i=temp;}
return t;
}
inline void j(int x,int y){r[q(x)]=q(y);}
inline bool in(int x,int y){return q(x)==q(y);}
inline bool chek(){
RP(t,1,n) r[t]=t;
sort(data+1,data+m+1);
long double ret=0;
RP(p,1,m)
if(!in(data[p].fr,data[p].to))
ret+=data[p].t*mid+data[p].w,j(data[p].fr,data[p].to);
return ret<=F+EPS||ret+EPS<=F;
}
int t1,t2,t3,t4;
int main(){
#ifndef ONLINE_JUDGE
freopen("quake.in","r",stdin);
freopen("quake.out","w",stdout);
#endif
n=qr(1);m=qr(1);F=qr(1);
RP(t,1,m){
t1=qr(1);
t2=qr(1);
t3=qr(1);
t4=qr(1);
add(t1,t2,t3,t4);
}
long double l=0,r=2000000001;
mid=0;
if(!chek()){
puts("0.0000\n");
return 0;
}
do{
mid=(l+r)/(db)2;
if(chek())
l=mid;
else
r=mid;
}while(l+EPS<r);
printf("%.4Lf",l);
return 0;
}
/*
分数形式?考虑数学表示一下
### $\frac{f-\Sigma c_i}{\Sigma t_i}\le ans$
### $f-\Sigma c_i\le ans\Sigma t_i$
### $\Sigma(ans\times t_i + c_i) \le f$
二分就完事了
*/
【题解】quake的更多相关文章
- 2016 华南师大ACM校赛 SCNUCPC 非官方题解
我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...
- noip2016十连测题解
以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...
- BZOJ-2561-最小生成树 题解(最小割)
2561: 最小生成树(题解) Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1628 Solved: 786 传送门:http://www.lyd ...
- Codeforces Round #353 (Div. 2) ABCDE 题解 python
Problems # Name A Infinite Sequence standard input/output 1 s, 256 MB x3509 B Restoring P ...
- 哈尔滨理工大学ACM全国邀请赛(网络同步赛)题解
题目链接 提交连接:http://acm-software.hrbust.edu.cn/problemset.php?page=5 1470-1482 只做出来四道比较水的题目,还需要加强中等题的训练 ...
- 2016ACM青岛区域赛题解
A.Relic Discovery_hdu5982 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Jav ...
- poj1399 hoj1037 Direct Visibility 题解 (宽搜)
http://poj.org/problem?id=1399 http://acm.hit.edu.cn/hoj/problem/view?id=1037 题意: 在一个最多200*200的minec ...
- 网络流n题 题解
学会了网络流,就经常闲的没事儿刷网络流--于是乎来一发题解. 1. COGS2093 花园的守护之神 题意:给定一个带权无向图,问至少删除多少条边才能使得s-t最短路的长度变长. 用Dijkstra或 ...
- CF100965C题解..
求方程 \[ \begin{array}\\ \sum_{i=1}^n x_i & \equiv & a_1 \pmod{p} \\ \sum_{i=1}^n x_i^2 & ...
随机推荐
- CentOS7安装部署jumpserver0.5
组件说明 Jumpserver为管理后台,管理员可以通过Web页面进行资产管理.用户管理.资产授权等操作; Coco为SSH Server和Web Terminal Server.用户可以通过使用自己 ...
- Java IO 流 设计模式
学过装饰模式后,大家会发现,它在Java语言中最著名的应用莫过于Java I/O标准为库的设计了.这一节将以处理Byte流为例,看看装饰模式是怎样得到应用的. 为什么不用继承而用装饰模式 我们知道Ja ...
- Css 基础学习
css 基本选择器 css基本选择器有三种方法 第一种: class选择器 .c1{ color: red;} <div class='c1'>hello world</div> ...
- 轻量i3wm配置使用笔记 -- 主题切换器(j4-make-config)
快速切换主题 j4-make-config介绍: j4-make-config脚本可以方便地在几组"主题"之间切换,还可以根据当前工作的环境,轻松地从几个不同的配置部分组合一个完整 ...
- eclipse中mybatis generator插件的安装与使用,实现自动生成代码
git地址:https://github.com/mybatis/generator 下载后解压: 选择任意一个版本的jar放到eclipse的features目录下即可 选择任意一个版本的jar放到 ...
- iOS7开发技巧
和任何新的iOS版本一样,有着一堆堆的新技巧和修改需要处理.有些我并不会立即遇到,所以这篇文章并不是一套完整技巧汇总.只是分享一些我碰巧遇到的问题. 如果你有任何更多的发现,可以发Twitter或者e ...
- wmware下载地址
https://my.vmware.com/cn/group/vmware/info?slug=desktop_end_user_computing/vmware_workstation/8_0 粗体 ...
- win7安装mysql解压缩版
http://blog.csdn.net/u013067166/article/details/49951577
- Win7如何解决精简版的迅雷7无法运行
网上下载msvcp71.dll和msvcr71.dll把文件放到System32目录下即可 http://www.baidu.com/s?wd=msvcp71.dll&ie=utf-8&a ...
- Solidworks如何生成爆炸图
1 自动爆炸 点击"爆炸视图"按钮,然后全部选中装配体(被选中的零件会变为蓝色,全部选中即全部变色)然后在组成偶尔的爆炸窗口中下拉,点击应用. 再点击完成 回到装配体面板, ...