POJ 1860 Currency Exchange(Bellman-Ford)
来源:互联网 发布:java全栈开发 编辑:程序博客网 时间:2024/04/29 11:07
题意 : 有关汇率的问题,汇率rab,增加了一个手续费 cab 每次的结果是 (本金 - 手续费) * 汇率,而且一个人拥有的钱的类型是已知的,拥有的value 钱的个数也是已知的, 问你能不能增值。
思路: 在Bellonman原本的实现过程中,是寻找最短路,判断负环。这一题恰好相反,需寻找最长路,判断有无无限松弛的正环
#include <iostream>#include <algorithm>#include <cstdio>#include <cmath>#include <cstring>#include <string.h>using namespace std;int n;int m;int s;double v;int sum;double dis[110];struct huilv{int a;int b;double r;double c;}hui[220];int bellman(){memset(dis,0,sizeof(dis));dis[s] = v;int flag;for(int i = 1;i < n; i++){ flag = 0;for(int j = 0;j < sum; j++)if(dis[hui[j].b] < (dis[hui[j].a] - hui[j].c) * hui[j].r){dis[hui[j].b] = (dis[hui[j].a] - hui[j].c) * hui[j].r;flag = 1;}if(!flag) break;}for(int i = 0;i < sum; i++)if(dis[hui[i].b] < (dis[hui[i].a] - hui[i].c) * hui[i].r)return 1;return 0;}int main(){int a,b;double rab,cab,rba,cba;while(cin>>n>>m>>s>>v){ sum = 0;for(int i = 0;i < m;i++){cin>>a>>b>>rab>>cab>>rba>>cba;hui[sum].a = a;hui[sum].b = b;hui[sum].r = rab;hui[sum++].c = cab;hui[sum].a = b;hui[sum].b = a;hui[sum].r = rba;hui[sum++].c = cba;} if(bellman()) cout<<"YES"<<endl; else cout<<"NO"<<endl;}return 0;}
0 0
- POJ 1860 Currency Exchange Bellman-Ford
- POJ-1860-Currency Exchange-Bellman-ford
- poj 1860 Currency Exchange :bellman-ford
- POJ 1860 Currency Exchange(Bellman-Ford)
- POJ 1860 Currency Exchange(Bellman-Ford)
- poj 1860 Currency Exchange(bellman-ford)
- Bellman-Ford-POJ-1860-Currency Exchange
- POJ 1860 Currency Exchange(Bellman-Ford)
- poj 1860 Currency Exchange 【bellman-ford】
- poj 1860 Currency Exchange (Bellman- Ford)
- POJ-1860 Currency Exchange(Bellman-Ford)
- poj 1860 Currency Exchange(bellman-ford)
- ZOJ 1544 / POJ 1860 Currency Exchange(bellman-ford)
- zoj 1544 || poj 1860 Currency Exchange(Bellman-ford)
- POJ 1860Currency Exchange (最短路径.Bellman-Ford)
- Poj 1860 Currency Exchange(Bellman-Ford,SPFA解单源最短路径问题)
- POJ 1860 Currency Exchange(最短路 Bellman-Ford)
- POJ 1860 Currency Exchange (Bellman-Ford 找正环)
- 括号匹配之添加最少括号匹配
- TCP/IP学习笔记(二)IP网际协议
- Camera图像处理原理及实例分析-重要图像概念
- MySQL Apply Security Settings安装不成功的解决方案
- C++反汇编->加法分析
- POJ 1860 Currency Exchange(Bellman-Ford)
- jQuery中$.get、$.post、$.getJSON和$.ajax的用法
- usaco Mixing Milk
- 一个linux兼容性问题的探讨---SElinux
- Linux文件编程--系统调用
- matlab中将字符串视为语句运行的方法——eval()函数
- 第5周作业-字体设置
- 【动态更新】java小技巧随记
- 高校俱乐部(-3+1)题解