当前位置:网站首页>【补题日记】[2022牛客暑期多校2]D-Link with Game Glitch
【补题日记】[2022牛客暑期多校2]D-Link with Game Glitch
2022-07-28 11:08:00 【cls1277】
Pro
https://ac.nowcoder.com/acm/problem/239341
Sol
建图就是从b到d连一条 c a \frac{c}{a} ac的边,所以问题可以转化为,当图中每条边的权值都乘w后,图中都会存在一个环,其边权之积大于1,求不满足此条件的w最大值。
答案存在单调性,即w越大时边权之积越大,反之成立。那么考虑二分w,此处边权之积可能很大,所以对其取log,则转化为与0之间的比较,即判断正负环的问题,可以直接套用spfa求负环的模板。
Code
//By cls1277
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define Fo(i,a,b) for(LL i=(a); i<=(b); i++)
#define Ro(i,b,a) for(LL i=(b); i>=(a); i--)
#define Eo(i,x,_) for(LL i=head[x]; i; i=_[i].next)
#define Ms(a,b) memset((a),(b),sizeof(a))
#define endl '\n'
const LL maxn = 1005;
const LL maxm = 2005;
const double eps = 1e-10;
LL n, m, head[maxn], tot, cnt[maxn];
double dis[maxn];
bool vis[maxn];
struct Edge {
LL to, next; double len;
}e[maxm];
void add(LL x, LL y, double z) {
tot++;
e[tot].next = head[x];
e[tot].to = y;
e[tot].len = z;
head[x] = tot;
}
bool judge(double w) {
queue<LL>q;
for(int i=1; i<=n; i++) {
dis[i] = 0;
cnt[i] = vis[i] = 0;
q.push(i);
}
while(!q.empty()) {
LL u = q.front();
q.pop();
vis[u] = 0;
for(int i=head[u]; i; i=e[i].next) {
LL v = e[i].to;
if(dis[v]>dis[u]+e[i].len+w) {
dis[v] = dis[u]+e[i].len+w;
if(!vis[v]) {
vis[v] = 1;
q.push(v);
cnt[v] = cnt[u]+1;
if(cnt[v]>=n) return 1;
}
}
}
}
return 0;
}
int main() {
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
#ifdef DEBUG
freopen("data.txt","r",stdin);
#endif
cin>>n>>m;
Fo(i,1,m) {
LL a, b, c, d; cin>>a>>b>>c>>d;
add(b, d, -log(c*1.0/a));
}
double l=0, r=1;
while(r-l>eps) {
double mid = (l+r)/2;
if(judge(-log(mid))) r = mid;
else l = mid;
}
// cout<<l;
printf("%.10lf",l);
return 0;
}
边栏推荐
- Introduction to web security RADIUS protocol application
- 对话庄表伟:开源第一课
- [half understood] zero value copy
- MySQL离线同步到odps的时候 可以配置动态分区吗
- Why does MySQL sometimes choose the wrong index?
- Leecode8 string conversion integer (ATOI)
- 接口测试的作用
- Summary of common RSA related problems in CTF: basic RSA encryption and decryption
- Database advanced learning notes -- object type
- Update dev (development version) of the latest win11
猜你喜欢

中国业务型CDP白皮书 | 爱分析报告

LabVIEW AI visual Toolkit (non Ni vision) download and installation tutorial

Minikube initial experience environment construction
![[geek challenge 2019] babysql-1 | SQL injection](/img/21/b5b4727178a585e610d743e92248f7.png)
[geek challenge 2019] babysql-1 | SQL injection

In order to ensure the normal operation of fire-fighting equipment in large buildings, the power supply monitoring system of fire-fighting equipment plays a key role

Byte side: how to realize reliable transmission with UDP?

Open source huizhichuang future | 2022 open atom global open source summit openatom openeuler sub forum was successfully held
![[pyGame practice] when the end of the world comes, how long can you live in a cruel survival game that really starts from scratch?](/img/2b/1eb02249ab9ad0b4e1bfeeee87418c.png)
[pyGame practice] when the end of the world comes, how long can you live in a cruel survival game that really starts from scratch?
![[applet] how to notify users of wechat applet version update?](/img/04/848a3d2932e0dc73adb6683c4dca7a.png)
[applet] how to notify users of wechat applet version update?

PFP会是数字藏品的未来吗?
随机推荐
可视化大型时间序列的技巧。
Can dynamic partitions be configured when MySQL is offline synchronized to ODPs
How to effectively implement a rapid and reasonable safety evacuation system in hospitals
go status. Go status code definition
B2 sub theme / blog b2child sub theme / open source code
Autumn recruit offer harvesters, and take the offers of major manufacturers at will
b2子主题/博客b2child子主题/开源源码
Using C language to compile student achievement management system (C language student achievement management system deleted)
Two point, three point, 01 point plan [bullet I]
擦黑板特效表白H5源码+非常浪漫/附BGM
数字孪生轨道交通:“智慧化”监控疏通城市运行痛点
An example of the mandatory measures of Microsoft edge browser tracking prevention
一文看懂设备指纹如何防篡改、防劫持
PKG packaging node project
AlexNet—论文分析及复现
[general database integrated development environment] Shanghai daoning provides you with Aqua Data Studio downloads, tutorials, and trials
Server online speed measurement system source code
"Node learning notes" koa framework learning
对话庄表伟:开源第一课
Solutions to slow start of MATLAB