当前位置:网站首页>【补题日记】[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;
}
边栏推荐
- 擦黑板特效表白H5源码+非常浪漫/附BGM
- R language uses LM function to build regression model with interactive items, and uses: sign (colon) to represent the interaction of variables (colon is pure multiplication, excluding the constituent
- ripro9.0修正升级版+WP两款美化包+稀有插件
- WPF layout controls are scaled up and down with the window, which is suitable for multi-resolution full screen filling applications
- Display line number under VIM command [easy to understand]
- Object to object mapping -automapper
- 1331. Array sequence number conversion
- How to effectively implement a rapid and reasonable safety evacuation system in hospitals
- Function of interface test
- postgres概述
猜你喜欢

What kind of knowledge payment system functions are more conducive to the development of the platform and lecturers?

Today's sleep quality record 74 points

Jupiter、spyder、Anaconda Prompt 、navigator 快捷键消失的解决办法

Introduction to the usage of SAP ui5 image display control avatar trial version

Cvpr2020 best paper: unsupervised learning of symmetric deformable 3D objects

Byte side: how to realize reliable transmission with UDP?

使用 Terraform 在 AWS 上快速部署 MQTT 集群

Ripro9.0 revised and upgraded version +wp two beautification packages + rare plug-ins

Cvpr2021 pedestrian re identification /person re identification paper + summary of open source code
![ASP. Net core 6 framework unveiling example demonstration [29]: building a file server](/img/90/40869d7c03f09010beb989af07e2f0.png)
ASP. Net core 6 framework unveiling example demonstration [29]: building a file server
随机推荐
MySQL (version 8.0.16) command and description
Can dynamic partitions be configured when MySQL is offline synchronized to ODPs
Learning notes tree array
移动端人脸风格化技术的应用
什么是WordPress
Today's sleep quality record 74 points
LabVIEW AI visual Toolkit (non Ni vision) download and installation tutorial
Digital twin rail transit: "intelligent" monitoring to clear the pain points of urban operation
The fifth generation verification code of "cloud centered, insensitive and extremely fast" is coming heavily
What is the process of switching c read / write files from user mode to kernel mode?
What functions does MySQL have? Don't look everywhere. Just look at this.
Design a system that supports millions of users
Why does acid food hurt teeth + early periodontitis
小水滴2.0网站导航网模板
Using C language to realize bidirectional linked list
R language uses LM function to build regression model and regression model for transformed data (for example, it is necessary to build regression model for X and y, but they have no linear relationshi
Ten thousand words detailed Google play online application standard package format AAB
Google Earth Engine——使用geetool批量下载单景影像以Landsat 8 反演后的NDSI结果
Database advanced learning notes - system package
Function of interface test