当前位置:网站首页>[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;
}
边栏推荐
- LabVIEW AI视觉工具包(非NI Vision)下载与安装教程
- 一些多参数函数的具体作用
- Service workers let the website dynamically load webp pictures
- 哪位大神帮看下 oracle number类型解析 怎么搞 Struct{scale=15,val
- Object stream of i/o operation (serialization and deserialization)
- 15、用户web层服务(三)
- Update dev (development version) of the latest win11
- R language ggplot2 visualization: ggdensity function of ggpubr package visualizes density graph and uses stat_ overlay_ normal_ Density function superimposes positive distribution curve, custom config
- P5472 [noi2019] douzhudi (expectation, Mathematics)
- AlexNet—论文分析及复现
猜你喜欢

Sirius network verification source code / official genuine / included building tutorial

Today's sleep quality record 74 points

Direct insert sort and Hill sort

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

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

Consumer installation and configuration

A hundred flowers bloom in data analysis engines. Why invest heavily in Clickhouse?

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

Outlook suddenly becomes very slow and too laggy. How to solve it

Autumn recruit offer harvesters, and take the offers of major manufacturers at will
随机推荐
R语言-用于非平衡数据集的一些度量指标
Database advanced learning notes -- object type
The reflect mechanism obtains the attribute and method information of class
Zotero document manager and its use posture (updated from time to time)
Go deadlock - when the channel meets mutex
Why does acid food hurt teeth + early periodontitis
How is the JS code compiled and executed by the browser engine?
Boutique scheme | Haitai Fangyuan full stack data security management scheme sets a "security lock" for data
How async await implements concurrency
拥抱开源指南
Interfaces and abstract classes
LabVIEW AI视觉工具包(非NI Vision)下载与安装教程
[general database integrated development environment] Shanghai daoning provides you with Aqua Data Studio downloads, tutorials, and trials
14、用户web层服务(二)
LabVIEW AI visual Toolkit (non Ni vision) download and installation tutorial
A new mode of one-stop fixed asset management
Network communication protocol classification and IP address
一文看懂设备指纹如何防篡改、防劫持
AlexNet—论文分析及复现
[collection] Advanced Mathematics: Capriccio of stars