当前位置:网站首页>[diary of supplementary questions] [2022 Niuke summer multi school 2] D-Link with game glitch
[diary of supplementary questions] [2022 Niuke summer multi school 2] D-Link with game glitch
2022-07-28 11:54:00 【cls1277】
Pro
https://ac.nowcoder.com/acm/problem/239341
Sol
Building a map is from b To d One in a row c a \frac{c}{a} ac The edge of , So the problem can be transformed into , When the weight of each edge in the graph is multiplied by w after , There will be a ring in the graph , The product of its edge weight is greater than 1, If this condition is not satisfied w Maximum .
The answer is monotonous , namely w The larger the boundary weight, the larger the product , Otherwise, it is established . Then consider two points w, The product of edge weight here may be very large , So take it log, Then it is transformed into and 0 Comparison between , That is, the problem of judging positive and negative rings , You can apply it directly spfa Find the template of negative ring .
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;
}
边栏推荐
- Anonymous subclass objects of abstract classes
- Database advanced learning notes cursor
- A hundred flowers bloom in data analysis engines. Why invest heavily in Clickhouse?
- Techniques for visualizing large time series.
- Full version of H5 social chat platform source code [complete database + complete document tutorial]
- How to use JWT for authentication and authorization
- mysql(8.0.16版)命令及说明
- Zotero document manager and its use posture (updated from time to time)
- Why does acid food hurt teeth + early periodontitis
- 什么是WordPress
猜你喜欢

Six papers that must be seen in the field of target detection

Three methods of using unity mouse to drive objects

目标检测领域必看的6篇论文

「以云为核,无感极速」第五代验证码重磅来袭

14、用户web层服务(二)

Simple selection sort and heap sort

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

Will PFP be the future of digital collections?

Redis安装

Leecode8 string conversion integer (ATOI)
随机推荐
Why does acid food hurt teeth + early periodontitis
What is the process of switching c read / write files from user mode to kernel mode?
Boutique scheme | Haitai Fangyuan full stack data security management scheme sets a "security lock" for data
Digital twin rail transit: "intelligent" monitoring to clear the pain points of urban operation
哪位大神帮看下 oracle number类型解析 怎么搞 Struct{scale=15,val
保障邮箱安全,验证码四个优势
Summary of common RSA related problems in CTF: basic RSA encryption and decryption
Server online speed measurement system source code
Embrace open source guidelines
【补题日记】[2022杭电暑期多校2]K-DOS Card
A lock faster than read-write lock. Don't get to know it quickly
学会使用MySQL的Explain执行计划,SQL性能调优从此不再困难
Outlook suddenly becomes very slow and too laggy. How to solve it
R language - some metrics for unbalanced data sets
[极客大挑战 2019]BabySQL-1|SQL注入
jar 包内文件的遍历以及文件的拷贝
Sirius network verification source code / official genuine / included building tutorial
Full version of H5 social chat platform source code [complete database + complete document tutorial]
SkiaSharp 之 WPF 自绘 拖曳小球(案例版)
How async await implements concurrency