【题解】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.3 开放端口 防火墙端口
1. 查看已打开的端口 # netstat -anp 2. 查看想开的端口是否已开 # firewall-cmd --query-port=666/tcp 若此提示 FirewallD is not ...
- Windows 10系统出现:“出现系统还原使用的卷影复制服务无法运行...”的问题解决
在服务中是:Volume Shadow Copy和Microsoft Software Shadow Copy Provider这两项.把它开启.
- php 列出当前目录
$path="."; //初使化用户所操作目录 $prevpath=dirname($path); //初使化当前脚本所在目录 $dir_handle=opendir($path) ...
- vuex 中关于 mapGetters 的作用
mapGetters 工具函数会将 store 中的 getter 映射到局部计算属性中.它的功能和 mapState 非常类似,我们来直接看它的实现: export function mapGett ...
- c# out ref
out 关键字会导致参数通过引用来传递.这与 ref 关键字类似,不同之处在于 ref 要求变量必须在传递之前进行初始化.若要使用 out 参数,方法定义和调用方法都必须显式使用 out 关键字.例如 ...
- SharePoint 的PowerShell命令之获取所有网站模版
Get-SPWebTemplate | select Name, Title
- ssh登录慢的解决办法
ubuntu的ssh登录有点慢,其实是很慢 google了一把,发现可以这样解决: (1)可能是DNS反向解析的问题 对于这样的问题,可以在/etc/ssh/sshd_config 中添加/修改: U ...
- TextView上的文字逐渐变淡直到消失
给TextView加个动画效果,完了在个动画加个监听,里面有个动画执行完调用的方法在方法里面把TextView设置为gone,我觉得你直接加这个动画效果之后他就会不显示了,其实他还在那占有位置呢.想不 ...
- LVS-DR,real-server为windows 2008的配置
LVS-DR,real-server为windows 2008的配置 部署邮件系统负载均衡,采用LVS-DR模式,调度器是一台centos 5.8,real-server是两台windows2008, ...
- 开发ActiveX控件调用另一个ActiveX系列0——身份证识别仪驱动的问题
程序员要从0下表开始,这篇是介绍这个系列的背景的,没有兴趣的人可以直接跳过. 为什么要开发ActiveX控件 由于工作需要,我们开发了一个网站,使用了一款身份证识别仪的网页ActiveX(OCX)插件 ...