当前位置:网站首页>"Wei Lai Cup" 2022 Niuke summer multi school training camp 2 d.[link with game glitch] two point answer +spfa ring
"Wei Lai Cup" 2022 Niuke summer multi school training camp 2 d.[link with game glitch] two point answer +spfa ring
2022-07-26 01:30:00 【HeartFireY】
D.Link with Game Glitch
Topic analysis
Yes m m m A recipe , Each recipe can be used k × a i k \times a_i k×ai individual b i b_i bi Raw material generation k × c i k \times c_i k×ci individual d i d_i di Grow raw materials . Now the request is k k k Multiply by a weight w w w, So that there is no situation that infinite items can be generated circularly among all recipes . Demand maximum m m m.
Obviously, it is necessary to generate infinite items , There needs to be a ring and the number of items generated along the ring is more than the original , That is, all edges on the ring have k ( c [ i ] − a [ i ] ) > 0 k(c[i] - a[i]) > 0 k(c[i]−a[i])>0 That is to say k c [ i ] a [ i ] > 1 k\frac{c[i]}{a[i]} > 1 ka[i]c[i]>1.
Since there may be multiple rings , We just need to ensure that the maximum ring will not be generated circularly . Obviously, you can do it with two answers .
Code
#include <bits/stdc++.h>
//#pragma gcc optimize(2)
#define double long double
#define endl '\n'
using namespace std;
const int N = 2e3 + 10, MOD = 1e9 + 7;
const double EPS = 1e-8;
struct node{
int v; double w; };
vector<node> g[N];
int n, m, cnt[N];
double dis[N];
bitset<N> vis;
bool check(double x){
queue<int> q;
x = -log(x);
vis.set();
memset(dis, 0, sizeof(dis));
memset(cnt, 0, sizeof(cnt));
for(int i = 1; i <= n; i++) q.emplace(i);
while(q.size()){
int u = q.front(); q.pop();
vis.reset(u);
for(auto nxt : g[u]){
int v = nxt.v;
double w = nxt.w;
if(dis[v] > dis[u] + w + x){
dis[v] = dis[u] + w + x;
cnt[v] = cnt[u] + 1;
if(cnt[v] > n) return true;
if(!vis[v]){
q.emplace(v);
vis.set(v);
}
}
}
}
return false;
}
inline void solve(){
cin >> n >> m;
for(int i = 1; i <= m; i++){
int a, b, c, d; cin >> a >> b >> c >> d;
g[b].emplace_back(node{
d, -log((1.0 * c) / a)});
}
double l = 0, r = 1;
for(int i = 1; i <= 300; i++){
double mid = (l + r) / 2;
if(check(mid)) r = mid;
else l = mid;
}
cout << l << endl;
}
signed main(){
ios_base::sync_with_stdio(false), cin.tie(0);
cout << fixed << setprecision(12);
int t = 1; //cin >> t;
while(t--) solve();
return 0;
}
边栏推荐
- U++学习笔记 UStruct、UEnum声明以及函数库简单函数实现
- I want to know how much the Commission is for opening an account. Is it safe to open an account on your mobile phone
- Creation and management of MySQL database and table
- Redis数据结构详解,结合书本
- Ideal Path(UVA - 1599)
- FreeBSD bNXT Ethernet driver source code reading record 2:
- Failed to load DLL
- 如何获取广告服务流量变现数据,助力广告效果分析?
- Fastjason handles generics
- 全国一半人跑长沙,长沙一半人跑哪?
猜你喜欢

NIO简易示例

Understand Linglong platform unified access service from simple to deep Monet

机器学习:贝叶斯网络

Linked list related interview questions

谷歌浏览器调试工具使用基础版(一)

"Yuanqi Cola" is not the end point, "China Cola" is

格式化JS代码,调试JS代码

Special topic of distributed micro service e-commerce (I) - Project Introduction

Introduction to API testing

Working principle of ZK rollups
随机推荐
Stack Title: basic calculator
Mysql_ Note2
Google gson usage details
言语理解中心理解总结
“元气可乐”不是终点,“中国可乐”才是
C语言中的整型数据类型(你真的了解吗)
快速创建题目文件夹
Understand Linglong platform unified access service from simple to deep Monet
4QAM、16QAM 调制与解调仿真电路,观察并分析QAM星座图和误码率曲线【matlab代码】
Leetcode537. 复数乘法(可以,已解决)
“蔚来杯“2022牛客暑期多校训练营2 H.[Take the Elevator] 维护线段
poj1521
Is it safe to buy funds on e fund? Professional answers
Tutorial on principles and applications of database system (053) -- MySQL query (XV): usage of character functions
链表相关面试题
数据库系统原理与应用教程(055)—— MySQL 查询(十七):数学函数的用法
C语言进阶(一)动态分配内存
推荐⼀款超好⽤的UI⾃动化⼯具: UiAutomator2!
Basic version of Google browser debugging tool (I)
8. Learn Mysql to create data tables