当前位置:网站首页>“蔚来杯“2022牛客暑期多校训练营2 D.[Link with Game Glitch] 二分答案+SPFA判环
“蔚来杯“2022牛客暑期多校训练营2 D.[Link with Game Glitch] 二分答案+SPFA判环
2022-07-26 01:23:00 【HeartFireY】
D.Link with Game Glitch
题目分析
有 m m m个配方,每个配方可以使用 k × a i k \times a_i k×ai个 b i b_i bi种原料生成 k × c i k \times c_i k×ci个 d i d_i di种原料。现在要求在 k k k上乘一个权值 w w w,使得所有配方间不存在可以循环生成无限物品的局面。要求最大化 m m m。
显然要生成无限物品,需要存在一个环且沿该环生成一轮得到的物品数目比原来更多,即为环上满足所有的边有 k ( c [ i ] − a [ i ] ) > 0 k(c[i] - a[i]) > 0 k(c[i]−a[i])>0即为 k c [ i ] a [ i ] > 1 k\frac{c[i]}{a[i]} > 1 ka[i]c[i]>1。
由于可能存在多个环,我们只需要保证最大环不会循环生成即可。显然可以二分答案来做。
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;
}
边栏推荐
- The application and principle of changing IP software are very wide. Four methods of dynamic IP replacement are used to protect network privacy
- [go] how to control the maximum number of concurrent processes
- Detailed explanation of at and crontab commands of RHCE and deployment of Chrony
- Google Gson用法详解
- Basic version of Google browser debugging tool (I)
- 【ICKIM 2022】第四届知识与信息管理国际会议
- Centrosymmetric binary mode cslbp, matlab
- 【Go】如何控制协程的最大并发数
- Arthas watch 命令查看数组中对象的属性
- How to switch IP and move bricks with mobile game simulator
猜你喜欢

Jushi | Haitai Fangyuan appears at the 5th Digital China Construction Summit
![[Go]三、最简单的RestFul API服务器](/img/1f/f6fc8cc9a3891d01a25e709170188d.png)
[Go]三、最简单的RestFul API服务器

U++ learning notes ustruct, uenum declaration and function library simple function implementation

全国一半人跑长沙,长沙一半人跑哪?

RHCE之at和crontab命令详解及chrony部署

Leetcode 537. complex multiplication (netizens' thoughts, ashamed)

Modify CSV

当博客被黑客攻击时该怎么办?

如何获取广告服务流量变现数据,助力广告效果分析?

What if win11 cannot open its own anti-virus software? Win11's built-in anti-virus function cannot be turned on
随机推荐
Nodejs builds cloud native microservice applications based on dapr, a quick start guide from 0 to 1
B - Krypton Factor (dfs+ backtracking method)
"Introduction to natural language processing practice" deep learning foundation - attention mechanism, transformer deep analysis and learning material summary
I want to know how much the Commission is for opening an account. Is it safe to open an account on your mobile phone
TV software burning
[ickim 2022] the Fourth International Conference on knowledge and information management
NodeJS 基于 Dapr 构建云原生微服务应用,从 0 到 1 快速上手指南
What are the ways to quickly improve programming skills in the process of programming learning?
Oracle - isupplier portal Invoicing error
Special topic of distributed micro service e-commerce (I) - Project Introduction
I just test it
U++学习笔记 UStruct、UEnum声明以及函数库简单函数实现
【数据挖掘】生成模型和判别模型的区别及优缺点
Failed to load DLL
Redis数据结构详解,结合书本
8、学习MySQL 创建数据表
B - Krypton Factor(dfs+回溯法)
[secsha concept] large and small end
Dot screen precautions
Test questions and answers of the latest Beijing Construction eight (materialman) mock examination in 2022