当前位置:网站首页>Link with Game Glitch
Link with Game Glitch
2022-08-02 07:49:00 【to cling】
Problem
给出n种物品,These items can be converted.给出m条转换规则,形如: a a a 个 b b b 物品 可以转换为 c × w c \times w c×w 个 d d d 物品.问: w w w How much to take,In order to prevent these items from being converted into an infinite number of items.
Solution
It's obviously a graph theory question.边: c → d c \to d c→d, 边权: c w a \frac{cw}{a} acw
- To make it impossible to convert into an infinite number of items,Then it is necessary to determine whether such one exists“环”.
假设:The edge weights on this ring are e i e_i ei, 环上有 k k k 个节点
那么,当满足 e 1 × e 2 × . . . × e k > 1 e_1 \times e_2 \times ... \times e_k > 1 e1×e2×...×ek>1 时, can be converted into an infinite number of items - 考虑到精度问题,Logarithms can be taken left and right
l o g ( e 1 × e 2 × . . . × e k ) > l o g ( 1 ) = 0 log(e_1 \times e_2 \times ... \times e_k) > log(1) = 0 log(e1×e2×...×ek)>log(1)=0
即: l o g ( e 1 ) + l o g ( e 2 ) + . . . + l o g ( e k ) > 0 − l o g ( e 1 ) − l o g ( e 2 ) − . . . − l o g ( e k ) < 0 log(e_1) + log(e_2) + ... + log(e_k) > 0 \\ -log(e_1) - log(e_2) - ... - log(e_k) < 0 log(e1)+log(e2)+...+log(ek)>0−log(e1)−log(e2)−...−log(ek)<0
到此为止,The title has been converted to side weights − l o g ( w c a ) -log(\frac {wc}{a}) −log(awc) the negative loop problem - 最后注意:The figure may be “森林“结构.
Code
const int N = 4e3 + 3;
int n, m;
int h[N], net[N], e[N], a[N], c[N], tot;
void add(int x, int y, int z, int zz)
{
e[++tot] = y;
a[tot] = z; c[tot] = zz;
net[tot] = h[x];
h[x] = tot;
}
double d[N];
int v[N], vis[N], cnt[N];
//vMarks whether the point is in the queue
//visMarks whether the point has been traveled,Used to traverse the forest structure
//cntThe number of updates to mark the point,更新次数 >= n 则存在负环
bool spfa(double w)
{
for (int i = 1; i <= n; i++)
d[i] = 1e18, v[i] = 0, vis[i] = 0;
for (int i = 1; i <= n; i++)
{
if (vis[i]) continue;
vis[i] = 1;
queue<int> q;
q.push(i);
d[i] = 0; v[i] = 1;
cnt[i] = 0;
while (sz(q))
{
int x = q.front(); q.pop();
v[x] = 0;
for (int i = h[x]; i; i = net[i])
{
int y = e[i]; double z = -log(w * c[i] / a[i]);
if (d[y] > d[x] + z)
{
vis[x] = 1;//标记走过的点
cnt[y] = cnt[x] + 1;
if (cnt[y] >= n) return 0;//find the negative ring
d[y] = d[x] + z;
if (v[y] == 0) q.push(y), v[y] = 1;
}
}
}
}
return 1;
}
int main()
{
IOS;
cin >> n >> m;
for (int i = 1, a, b, c, d; i <= m; i++)
{
cin >> a >> b >> c >> d;
add(b, d, a, c);
}
double l = 0, r = 1;
while (r - l > esp)
{
double mid = (l + r) / 2;
if (spfa(mid)) l = mid;
else r = mid;
}
cout << fixed << setprecision(10) << r << endl;
return 0;
}
边栏推荐
猜你喜欢

电商库存系统的防超卖和高并发扣减方案

初探形式化方法基本原理

mysql操作入门(四)-----数据排序(升序、降序、多字段排序)

概率论与数理统计

Agile, DevOps and Embedded Systems Testing

PWA 踩坑 - 第一次加载页面后无法获取CacheStorage某些资源

敏捷、DevOps和嵌入式系统测试

(2022牛客多校五)C-Bit Transmission(思维)

根据一个字段的内容去更新另一个字段的数据,这样的sql语句该怎么样书写

企业实训复现指导手册——基于华为ModelArts平台的OpenPose模型的训练和推理、基于关键点数据实现对攀爬和翻越护栏两种行为的识别、并完成在图片中只标注发生行为的人
随机推荐
php删除一维数组中一个值
Agile, DevOps and Embedded Systems Testing
Splunk Filed extraction 字段截取
队列题目:无法吃午餐的学生数量
交换--STP协议
查看端口号占用
初探形式化方法基本原理
张驰课堂:六西格玛培训工具——箱线图
OC-NSDictionary
【暑期每日一题】洛谷 P3156 【深基15.例1】询问学号
jvm 二之 栈帧内部结构
入门opencv,欢笑快乐每一天
你认同这个观点吗?大多数企业的数字化都只是为了缓解焦虑
【图像隐藏】基于matlab混合DWT-HD-SVD数字图像水印方法技术【含Matlab源码 2007期】
View zombie processes
MySQL-索引优化和查询优化
解决Pytorch模型在Gunicorn部署无法运行或者超时问题
Swagger的简单介绍,集成,以及如何在生产环境中关闭swagger,在测试和开发环境中自动打开
【云原生】如何快速部署Kubernetes
【机器学习】实验3布置:贝叶斯垃圾邮件识别