当前位置:网站首页>【补题日记】[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;
}
边栏推荐
- Iterative method for determinant (linear algebraic formula)
- Will PFP be the future of digital collections?
- I want to ask you guys, if there is a master-slave switch when CDC collects mysql, is there any solution
- Router firmware decryption idea
- ZBrush 2022 software installation package download and installation tutorial
- What kind of knowledge payment system functions are more conducive to the development of the platform and lecturers?
- PHP检测url网址链接是否正常可访问
- Object to object mapping -automapper
- [half understood] zero value copy
- What is the process of switching c read / write files from user mode to kernel mode?
猜你喜欢

天狼星网络验证源码/官方正版/内附搭建教程

What is the process of switching c read / write files from user mode to kernel mode?

Zotero document manager and its use posture (updated from time to time)

Software testing and quality learning notes 1 --- black box testing
![[half understood] zero value copy](/img/4b/c8140bf7ee4baa094ca3011108d686.gif)
[half understood] zero value copy

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

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

Quickly deploy mqtt clusters on AWS using terraform

PFP会是数字藏品的未来吗?

Six papers that must be seen in the field of target detection
随机推荐
Shell (II)
R language ggplot2 visualization: use the ggboxplot function of ggpubr package to visualize the box diagram and customize the fill parameter to configure the filling color of the box
1331. 数组序号转换
Sirius network verification source code / official genuine / included building tutorial
A natural choice
天狼星网络验证源码/官方正版/内附搭建教程
Shell (I)
Cvpr2020 best paper: unsupervised learning of symmetric deformable 3D objects
Five Ali technical experts have been offered. How many interview questions can you answer
Are interviews all about memorizing answers?
Introduction to web security RADIUS protocol application
Summary of common RSA related problems in CTF: basic RSA encryption and decryption
万字详解 Google Play 上架应用标准包格式 AAB
R language uses oneway The test function performs one-way ANOVA
Byte side: how to realize reliable transmission with UDP?
LabVIEW AI视觉工具包(非NI Vision)下载与安装教程
[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
【补题日记】[2022杭电暑期多校2]K-DOS Card
Blackboard cleaning effect shows H5 source code + very romantic / BGM attached