poj 1860 Currency Exchange(bellman-ford)
来源:互联网 发布:mysql 小于转义 编辑:程序博客网 时间:2024/04/29 08:51
货币兑换,使得货币最后再兑换回S的时候Nick的总资产是增加的,这就要使兑换货币的路径有一个正的回路,才可以使Nick的总资产是增加的。用bellman-ford找回路,回路存在,则YES,否则NO。
http://blog.csdn.net/yslcl12345/article/details/50574213,这个题解用的floyd做的,题目翻译的挺好的
#include <iostream>#include <cstring>using namespace std;int n,m,s;double v;int edge;double dis[101];struct point{ int a,b; double r,c;};point exc[202];bool bellmanFord(){ memset(dis,0,sizeof(dis)); dis[s] = v; bool flag; for(int i = 0; i < n-1; ++i) { flag = false; for(int j = 0; j < edge; ++j) { if(dis[exc[j].b] < (dis[exc[j].a] - exc[j].c)*exc[j].r) { flag = true; dis[exc[j].b] = (dis[exc[j].a] - exc[j].c)*exc[j].r; } } if(!flag) break; } for(int k = 0; k < edge; ++k) if(dis[exc[k].b] < (dis[exc[k].a] - exc[k].c)*exc[k].r) return true; return false;}int main(){ int a,b; double rab,cab,rba,cba; while(cin >> n >> m >> s >> v) { edge = 0; for(int i = 0; i < m; ++i) { cin >> a >> b >> rab >> cab >> rba >> cba; exc[edge].a = a; exc[edge].b = b; exc[edge].r = rab; exc[edge++].c = cab; exc[edge].a = b; exc[edge].b = a; exc[edge].r = rba; exc[edge++].c = cba; } if(bellmanFord()) 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 找正环)
- 207. Course Schedule**
- 两线段间的距离,三分法,计算几何(狗的距离,uva 11796)
- swapon--Linux命令应用大词典729个命令解读
- #ifndef...#endif 的用法
- Asterisk项目的前世今生
- poj 1860 Currency Exchange(bellman-ford)
- 两个<script>
- ACM_符号配对问题(C#)
- setfacl命令--Linux命令应用大词典729个命令解读
- org.springframework.beans.factory.BeanD...
- 安装Asterisk
- uva 10085 The most distant state
- NYOJ 58 最小的步数
- 安装Asterisk(一)安装AsteriskNOW