最短路径练习-POJ 1860 Currency Exchange
来源:互联网 发布:周立功单片机培训 编辑:程序博客网 时间:2024/06/01 22:03
题目大意:
多种汇币,汇币之间可以无限转换(存在手续费),问是否存在一种路径使金钱一直增加。
思路:
判断是否存在正权回路,用belman-Ford算法的变体 更改松弛条件 。
#include<stdio.h>#include<stdlib.h>#include <string.h>#define MAXINT 1100#define MAXD 999999struct edge{int u, v;double r, c;}ed[MAXINT];bool bellman_ford(int n, int v, double c, int e){double d[MAXINT];memset(d, 0, sizeof(d));d[v] = c;bool flag;for (int i = 1; i < n; i++){flag = false;for (int j = 0; j < e; j++)if (d[ed[j].v] < (d[ed[j].u] - ed[j].c)*ed[j].r){d[ed[j].v] = (d[ed[j].u] - ed[j].c)*ed[j].r;flag = true;}if (!flag)break;}for (int i = 0; i < e; i++)if (d[ed[i].v] < (d[ed[i].u] - ed[i].c)*ed[i].r)return true;return false;}int main(){int n, m, s;int x, y, e;double v, r1, c1, r2, c2;while (scanf("%d%d%d%lf", &n, &m, &s, &v) != EOF){e = 0;for (int i = 1; i <= m; i++){scanf("%d%d%lf%lf%lf%lf", &x, &y, &r1, &c1, &r2, &c2);ed[e].u = x;ed[e].v = y;ed[e].r = r1;ed[e++].c = c1;ed[e].u = y;ed[e].v = x;ed[e].r = r2;ed[e++].c = c2;}if (bellman_ford(n, s, v, e))printf("YES\n");elseprintf("NO\n");}return 0;}
0 0
- 最短路径练习-POJ 1860 Currency Exchange
- POJ 1860Currency Exchange (最短路径.Bellman-Ford)
- 初级->图算法->最短路径 poj 1860 Currency Exchange
- poj 1860 Currency Exchange 【最短路径-Bellman Ford】
- Currency Exchange(最短路径)
- POJ1860 Currency Exchange(最短路径)
- Currency Exchange--(最短路径算法)
- 最短路练习5/poj/1860 /Currency Exchange 有正环
- 最短路径___Currency Exchange ( Poj 1860 )
- poj 1860 -- Currency Exchange(最短路)
- poj 1860 Currency Exchange (最短路)
- POJ 1860 Currency Exchange(最短路)
- POJ 1860 Currency Exchange(最短路SPFA)
- POJ 1860Currency Exchange BFS最短路
- POJ - 1860 Currency Exchange(最短路)
- poj 1860 Currency Exchange(最短路)
- poj 1860Currency Exchange(bellman 最短路)
- POJ 1860 Currency Exchange(最短路)
- 跟着男票写程序1--opencv遍历图像像素
- [BZOJ 1053] [HAOI2007]反素数ant 数论+搜索
- 文章标题
- 如果点击事件截取,通过代理继续响应者链
- PostgreSQL & Oracle -1 OLTP "update/select based primary key" & insert
- 最短路径练习-POJ 1860 Currency Exchange
- Floyd传递闭包-POJ-3660-Cow Contest
- Core Location
- 网络原理,以及虚拟机相关配置
- POJ 1230 Pass-Muraille 贪心
- 【codevs3269】混合背包 背包DP裸题
- MAC安装MYSQL
- 比赛排名(猎豹笔试编程题)
- [Python]模拟键盘同时按下几个按键