POj1860(floyd+正权回路)
题意:有多种汇币,汇币之间可以交换,这需要手续费,当你用100A币交换B币时,A到B的汇率是29.75,手续费是0.39,那么你可以得到(100 - 0.39) * 29.75 = 2963.3975 B币。
题解:我们可以用货币种类编号建图,在图上任意两点表示兑换关系并且是双向的,值得注意的是货币A没有兑换是的权值是不变的,而A兑换成B那么B的权值就是(k-Cab)*Rab,那么我们只要Floyd跑一边。然后判断是否存在一个dis[v]>dis[i]+w;
代码:
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
using namespace std;
const int maxn=1e3+5;
double dis[maxn];
int n,m,o;
double sum;
struct node
{
int u,v;
double r,c;
}e[maxn];
bool floyd()
{
dis[o]=sum;
for(int k=1;k<=n;k++)
{
bool flag=false;
for(int i=0;i<2*m;i++)
{
int u=e[i].u;
int v=e[i].v;
double r=e[i].r;
double c=e[i].c;
if(dis[v]<(dis[u]-c)*r)
{
dis[v]=(dis[u]-c)*r;
flag=true;
}
}
if(!flag) break;
}
for(int i=0;i<2*m;i++)
{
int u=e[i].u;
int v=e[i].v;
double r=e[i].r;
double c=e[i].c;
if(dis[v]<(dis[u]-c)*r)
{
return true;
}
}
return false;
}
int main()
{
scanf("%d%d%d%lf",&n,&m,&o,&sum);
int k=0;
for(int i=1;i<=m;i++)
{
int a,b;
double r1,c1,r2,c2;
scanf("%d%d%lf%lf%lf%lf",&a,&b,&r1,&c1,&r2,&c2);
e[k].u=a;
e[k].v=b;
e[k].r=r1;
e[k].c=c1;
k++;
e[k].u=b;
e[k].v=a;
e[k].r=r2;
e[k].c=c2;
k++;
}
memset(dis,0,sizeof dis);
if(floyd()) puts("YES");
else puts("NO");
return 0;
}
POj1860(floyd+正权回路)的更多相关文章
- Bellman_ford货币兑换——正权回路判断
POJ1860 题目大意:你在某一点有一些钱,给定你两点之间钱得兑换规则,问你有没有办法使你手里的钱增多.就是想看看转一圈我的钱能不能增多,出现这一点得条件就是有兑换钱得正权回路,所以选择用bellm ...
- 图论 --- spfa + 链式向前星 : 判断是否存在正权回路 poj 1860 : Currency Exchange
Currency Exchange Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 19881 Accepted: 711 ...
- poj 1860 Currency Exchange (SPFA、正权回路 bellman-ford)
链接:poj 1860 题意:给定n中货币.以及它们之间的税率.A货币转化为B货币的公式为 B=(V-Cab)*Rab,当中V为A的货币量, 求货币S通过若干此转换,再转换为原本的货币时是否会添加 分 ...
- POJ1860-Currency Exchange (正权回路)【Bellman-Ford】
<题目链接> <转载于 >>> > 题目大意: 有多种汇币,汇币之间可以交换,这需要手续费,当你用100A币交换B币时,A到B的汇率是29.75,手续费是0. ...
- Currency Exchange 货币兑换 Bellman-Ford SPFA 判正权回路
Description Several currency exchange points are working in our city. Let us suppose that each point ...
- POJ 1860 Currency Exchange(最短路&spfa正权回路)题解
题意:n种钱,m种汇率转换,若ab汇率p,手续费q,则b=(a-q)*p,你有第s种钱v数量,问你能不能通过转化让你的s种钱变多? 思路:因为过程中可能有负权值,用spfa.求是否有正权回路,dis[ ...
- [ACM] hdu 1217 Arbitrage (bellman_ford最短路,推断是否有正权回路或Floyed)
Arbitrage Problem Description Arbitrage is the use of discrepancies in currency exchange rates to tr ...
- HDU - 1317 ~ SPFA正权回路的判断
题意:有最多一百个房间,房间之间连通,到达另一个房间会消耗能量值或者增加能量值,求是否能从一号房间到达n号房间. 看数据,有定5个房间,下面有5行,第 iii 行代表 iii 号 房间的信息,第一个数 ...
- POJ 3259 Wormholes(最短路&spfa正权回路)题解
题意:给你m条路花费时间(双向正权路径),w个虫洞返回时间(单向负权路径),问你他能不能走一圈回到原点之后,时间倒流. 思路:题意有点难看懂,我们建完边之后找一下是否存在负权回路,存在则能,反之不能. ...
随机推荐
- 计算机网络 part1 TCP
一.TCP协议 references:newcoder TCP/IP协议,TCP和UDP的区别及特点 1.四层模型 应用层:载有应用程序,将数据发送给传输层.主要协议有HTTP.SMTP.FTP.DN ...
- Linux的IO调度程序
Linux的IO调度机制浅析 现代计算机体系中,磁盘的速度和CPU的速度差距太大了,如果简单的将系统的IO请求按照请求的顺序进行顺序处理的话,系统的IO开销将导致系统的效率十分的低下,因此就需要将IO ...
- 2021-2-17:Java HashMap 的中 key 的哈希值是如何计算的,为何这么计算?
首先,我们知道 HashMap 的底层实现是开放地址法 + 链地址法的方式来实现. 即数组 + 链表的实现方式,通过计算哈希值,找到数组对应的位置,如果已存在元素,就加到这个位置的链表上.在 Java ...
- Pycharm缺少环境变量+无法获取libcudnn.so.6
在终端输入: echo LD_LIBRARY_PATH, 并将其内容 添加至Pycharm的 run -> Edit configuration -> Environment variab ...
- SVG background watermark
SVG background watermark SVG 背景水印 <svg xmlns="http://www.w3.org/2000/svg" width="2 ...
- GraphQL All In One
GraphQL All In One refs https://github.com/hasura/learn-graphql xgqfrms 2012-2020 www.cnblogs.com 发布 ...
- how to fetch a group promise api in order with the returned resolved result
how to fetch a group promise api in order with the returned resolved result promise 一组依次请求,generator ...
- 微信小程序-云开发-实战项目
微信小程序-云开发-实战项目 微信小程序 微信小程序平台服务条款 https://developers.weixin.qq.com/miniprogram/product/service.html h ...
- live chat for website UX
live chat for website UX increase customer satisfaction using a live chat https://crisp.chat/en/live ...
- nasm astrncat_s函数 x86
xxx.asm: %define p1 ebp+8 %define p2 ebp+12 %define p3 ebp+16 %define p4 ebp+20 section .text global ...