当前位置:网站首页>(2022 Niuke multi school) D-Link with game glitch (SPFA)
(2022 Niuke multi school) D-Link with game glitch (SPFA)
2022-07-25 05:45:00 【AC__ dream】
subject :
The sample input :
3 3
1 1 2 2
1 2 2 1
1 3 1 1Sample output :
0.5000000000The question : Given m A way of synthesizing objects , Find a maximum synthetic loss parameter w, So that all items cannot be obtained infinitely through infinite synthesis .
analysis : It should be noted that the greater the loss parameter value, the less the loss when the article is synthesized , So that is to say, this topic w Monotonicity , When w When reaching a boundary value ,w No matter how big, there will be some items that can be obtained indefinitely , and w No matter how small, all items can't be obtained indefinitely , So we can solve it directly by dichotomy .
For one w We judge whether it is feasible , Is equivalent to this topic :Arbitrage(spfa)_AC__dream The blog of -CSDN Blog w
Only need to run once spfa Judge whether there is a positive ring in the figure below to know whether there is an item that can be synthesized infinitely , But there is another very important point of this topic that needs special attention , That is to say a,c The boundary of the scope is 1e3, All in all 1000 Items , In extreme cases 1 After exchanging items, you will get 1e3000, This number is relatively large , The loss of accuracy will be serious , So we can't directly update the original data , We can Take the logarithm of the original data and then update it . To put it a little bit : If opened long double You can also put this topic ac, But I still hope you will pay attention to this skill .
W Is the loss parameter a[i] individual t Items can be exchanged c[i] individual j goods , be
Update method of original data :
if(d[t]*c[i]/a[i]*W>=d[j]) d[j]=d[t]*c[i]/a[i]*W
Update method after taking logarithm :
if(log(d[t])+log(c[i]/a[i])+log(W)>=log[d[j]]) log[d[j]=log(d[t])+log(c[i]/a[i])+log(W)
The basis of this transformation is log A function is monotonically increasing in its domain , So if d[t]*c[i]/a[i]*W>=d[j], Then there are log(d[t])+log(c[i]/a[i])+log(W)>=log[d[j]]. We directly order d[i]=log(d[i]), Then make w[i]=log(c[i]/a[i]),W=log(W) that will do , Then the update condition becomes :
if(d[t]+w[i]+W>d[j]) d[j]=d[t]+w[i]+W
Then just use one cnt The array can determine the positive ring , Be careful spfa Judge the ring , It is possible that the graph is not connected , So we need to add all points to the queue at the beginning . See code for details :
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
#include<queue>
#include<vector>
#include<cmath>
using namespace std;
const int N=1e4+10;
int h[N],e[N],ne[N],cnt[N],idx;
double w[N],d[N];
bool vis[N];
int n,m;
void add(int x,int y,double z)
{
e[idx]=y;
w[idx]=z;
ne[idx]=h[x];
h[x]=idx++;
}
bool spfa(double W)
{
W=log(W);
queue<int>q;
for(int i=1;i<=n;i++)
{
cnt[i]=0;
vis[i]=false;
q.push(i);
}
while(!q.empty())
{
int t=q.front();
q.pop();
vis[t]=false;
for(int i=h[t];i!=-1;i=ne[i])
{
int j=e[i];
if(d[t]+w[i]+W>d[j])
{
d[j]=d[t]+w[i]+W;
cnt[j]=cnt[t]+1;
if(cnt[j]>=n) return true;
if(!vis[j])
{
q.push(j);
vis[j]=true;
}
}
}
}
return false;
}
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++) h[i]=-1;
for(int i=1;i<=m;i++)
{
int a,b,c,d;
scanf("%d%d%d%d",&a,&b,&c,&d);
add(b,d,log(1.0*c/a));
}
double l=0.0,r=1.0;
while(r-l>1e-8)
{
double mid=(l+r)/2;
if(spfa(mid)) r=mid;// If there is a positive ring, you need to increase the loss rate
else l=mid;
}
printf("%.7lf",l);
return 0;
}边栏推荐
- C Programming -- the solution of dynamic programming of "the sum of the largest subarray"
- y76.第四章 Prometheus大厂监控体系及实战 -- prometheus进阶(七)
- HTB-Beep
- HTB-Granpa
- Vim配置Golang开发环境
- obj文件格式与.mtl文件格式
- Realsense D435i 深度图优化_高精度模式
- Differences and application directions of GPS, base station and IP positioning
- Productivity tool in the new era -- flowus information flow comprehensive evaluation
- 剑指 Offer 36. 二叉搜索树与双向链表
猜你喜欢

聊聊 Redis 是如何进行请求处理

Leetcode 237. 删除链表中的节点
![50: Chapter 5: develop admin management service: 3: develop [query whether the admin user name already exists, interface]; (this interface can only be called when logging in; so we have written an int](/img/1b/b8529b6f1d163a9e5d5dad2b78ce93.png)
50: Chapter 5: develop admin management service: 3: develop [query whether the admin user name already exists, interface]; (this interface can only be called when logging in; so we have written an int
![(14)[驱动开发]配置环境 VS2019 + WDK10 写 xp驱动](/img/90/0d94d26be8128d77de65919763fda5.png)
(14)[驱动开发]配置环境 VS2019 + WDK10 写 xp驱动

Softing pngate series gateway: integrate PROFIBUS bus into PROFINET network

HTB-Arctic

Three schemes for finclip to realize wechat authorized login

Unity accesses chartandgraph chart plug-in

Easyrecovery free data recovery tool is easy to operate and restore data with one click

systemverilog中function和task区别
随机推荐
Unity接入ChartAndGraph图表插件
leetcode/整数除法
VPP cannot load up status interface
Application of hard coding and streaming integration scheme based on spice protocol in cloud games
Big talk · book sharing | Haas Internet of things device cloud integrated development framework
systemverilog中function和task区别
sqlilabs less-29
2021年ICPC陕西省赛热身赛 B.CODE(位运算)
VIM configuring golang development environment
y76.第四章 Prometheus大厂监控体系及实战 -- prometheus进阶(七)
Working principle and precautions of bubble water level gauge
求求你别再用 System.currentTimeMillis() 统计代码耗时了,真的太 Low 了!
编程大杂烩(一)
Leetcode 237. delete nodes in the linked list
Summary of common attributes of flex layout
Three schemes for finclip to realize wechat authorized login
Y76. Chapter IV Prometheus large factory monitoring system and practice -- Prometheus advanced (VII)
Leetcode 202. 快乐数(一点都不快乐)
Introduction summary of using unirx in unity
Introduction to interface in SystemVerilog