当前位置:网站首页>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-FlinkCDC-Hudi实时入湖
根据一个字段的内容去更新另一个字段的数据,这样的sql语句该怎么样书写
条件构造器~wapper
FaceBook社媒营销高效转化技巧分享
System.Security.SecurityException: 未找到源,但未能搜索某些或全部事件日志。不可 访问的日志: Security
jvm 二之 栈帧内部结构
“蔚来杯“2022牛客暑期多校训练营5,签到题KBGHFCD
以训辅教,以战促学 | 新版攻防世界平台正式上线运营!
张驰课堂:六西格玛培训工具——箱线图
企业实训复现指导手册——基于华为ModelArts平台的OpenPose模型的训练和推理、基于关键点数据实现对攀爬和翻越护栏两种行为的识别、并完成在图片中只标注发生行为的人
随机推荐
实验7 MPLS实验
【机器学习】实验4布置:AAAI会议论文聚类分析
暑假第五周总结
实例026:递归求阶乘
跨阻放大器
“蔚来杯“2022牛客暑期多校训练营5,签到题KBGHFCD
JS初识高阶函数和函数柯里化
反射课后习题及做题记录
Xilinx约束学习笔记—— 时序约束
主流定时任务解决方案全横评
MySQL-数据库设计规范
线程的创建方式
【暑期每日一题】洛谷 P1255 数楼梯
获取间隔的日期列表工具类
【网络】IP、子网掩码
【CV】OpenVINO安装教程
【机器学习】实验3布置:贝叶斯垃圾邮件识别
CollectionUtil:一个函数式风格的集合工具
Splunk Filed Alias field name
(2022牛客多校五)C-Bit Transmission(思维)