POJ 1860 Currency Exchange (最短路)
Time Limit:1000MS Memory Limit:30000KB 64bit IO Format:%I64d & %I64u
System Crawler (2015-05-14)
Description
For example, if you want to exchange 100 US Dollars into Russian Rubles at the exchange point, where the exchange rate is 29.75, and the commission is 0.39 you will get (100 - 0.39) * 29.75 = 2963.3975RUR.
You surely know that there are N different currencies you can deal with in our city. Let us assign unique integer number from 1 to N to each currency. Then each exchange point can be described with 6 numbers: integer A and B - numbers of currencies it exchanges, and real R AB, CAB, R BA and C BA - exchange rates and commissions when exchanging A to B and B to A respectively.
Nick has some money in currency S and wonders if he can somehow, after some exchange operations, increase his capital. Of course, he wants to have his money in currency S in the end. Help him to answer this difficult question. Nick must always have non-negative sum of money while making his operations.
Input
For each point exchange rates and commissions are real, given with at most two digits after the decimal point, 10 -2<=rate<=10 2, 0<=commission<=10 2.
Let us call some sequence of the exchange operations simple if no exchange point is used more than once in this sequence. You may assume that ratio of the numeric values of the sums at the end and at the beginning of any simple sequence of the exchange operations will be less than 10 4.
Output
Sample Input
3 2 1 20.0
1 2 1.00 1.00 1.00 1.00
2 3 1.10 1.00 1.10 1.00
Sample Output
YES 松弛方法变反,最后检查是否有正环。
#include <iostream>
#include <cstdio>
using namespace std; int N,M,S;
double V;
double D[];
struct Node
{
int from,to;
double r,c;
}G[]; bool Bellman_Ford(void);
int main(void)
{
int from,to;
double box; while(scanf("%d%d%d%lf",&N,&M,&S,&V) != EOF)
{
for(int i = ;i < M * ;)
{
scanf("%d%d%lf%lf",&G[i].from,&G[i].to,&G[i].r,&G[i].c);
i ++;
G[i].from = G[i - ].to;
G[i].to = G[i - ].from;
scanf("%lf%lf",&G[i].r,&G[i].c);
i ++;
}
if(Bellman_Ford())
puts("YES");
else
puts("NO");
}
} bool Bellman_Ford(void)
{
bool update;
fill(D,D + ,);
D[S] = V; for(int i = ;i < N - ;i ++)
{
update = false;
for(int j = ;j < M * ;j ++)
if(D[G[j].to] < (D[G[j].from] - G[j].c) * G[j].r && (D[G[j].from] - G[j].c) * G[j].r >= )
{
update = true;
D[G[j].to] = (D[G[j].from] - G[j].c) * G[j].r;
if(D[S] > V)
return true;
}
if(!update)
break;
}
for(int i = ;i < M * ;i ++)
if(D[G[i].to] < (D[G[i].from] - G[i].c) * G[i].r)
return true;
return false;
}
POJ 1860 Currency Exchange (最短路)的更多相关文章
- POJ 1860 Currency Exchange 最短路+负环
原题链接:http://poj.org/problem?id=1860 Currency Exchange Time Limit: 1000MS Memory Limit: 30000K Tota ...
- poj 1860 Currency Exchange (最短路bellman_ford思想找正权环 最长路)
感觉最短路好神奇呀,刚开始我都 没想到用最短路 题目:http://poj.org/problem?id=1860 题意:有多种从a到b的汇率,在你汇钱的过程中还需要支付手续费,那么你所得的钱是 mo ...
- POJ 1860 Currency Exchange 最短路 难度:0
http://poj.org/problem?id=1860 #include <cstdio> //#include <queue> //#include <deque ...
- 最短路(Bellman_Ford) POJ 1860 Currency Exchange
题目传送门 /* 最短路(Bellman_Ford):求负环的思路,但是反过来用,即找正环 详细解释:http://blog.csdn.net/lyy289065406/article/details ...
- POJ 1860 Currency Exchange / ZOJ 1544 Currency Exchange (最短路径相关,spfa求环)
POJ 1860 Currency Exchange / ZOJ 1544 Currency Exchange (最短路径相关,spfa求环) Description Several currency ...
- POJ 1860 Currency Exchange + 2240 Arbitrage + 3259 Wormholes 解题报告
三道题都是考察最短路算法的判环.其中1860和2240判断正环,3259判断负环. 难度都不大,可以使用Bellman-ford算法,或者SPFA算法.也有用弗洛伊德算法的,笔者还不会SF-_-…… ...
- POJ 1860——Currency Exchange——————【最短路、SPFA判正环】
Currency Exchange Time Limit:1000MS Memory Limit:30000KB 64bit IO Format:%I64d & %I64u S ...
- POJ 1860 Currency Exchange (最短路)
Currency Exchange Time Limit : 2000/1000ms (Java/Other) Memory Limit : 60000/30000K (Java/Other) T ...
- POJ 1860 Currency Exchange【bellman_ford判断是否有正环——基础入门】
链接: http://poj.org/problem?id=1860 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...
随机推荐
- 转载 在 Linux 虚拟机中手动安装或升级 VMware Tools
http://pubs.vmware.com/workstation-12/index.jsp?lang=zh_CN&topic=/com.vmware.ws.using.doc/GUID-0 ...
- SecureCRT上传、下载文件(使用sz与rz命令)
1.简述 借助securtCRT,使用linux命令sz可以很方便的将服务器上的文件下载到本地,使用rz命令则是把本地文件上传到服务器. 2.理解记忆 其中,对于sz和rz的理解与记忆我用了如下的方法 ...
- C#中的Collection 1
Collection定义 Collection是个关于一些变量的集合,按功能可分为Lists,Dictionaries,Sets三个大类. Lists:是一个有序的集合,支持index look up ...
- C:内存分配、内存中五大区
1.内存的划分 (从高到低依次是: 栈区 . 堆区 .全局静态区 . 常量区 . 代码区 )栈区是系统自动回收,堆区是我们手动回收 2. 栈区 在函数内部定义的局部变量和数组.都存放在栈区, ...
- thinkphp 3+ 观后详解 (2)
接上一章的内容,我们继续来看Think.class.php文件的start方法 static public function start() { // 注册AUTOLOAD方法 spl_autoloa ...
- iOS 本地企业发布流程
今天和后台弄了一下本地企业ipa发布, 准备工具:要发布的ipa文件一个,一个plist plist文件格式内容: <?xml version="1.0" encoding= ...
- myeclipse、eclipse中项目复制后(可能无法访问)注意事项 .
.myEclipse 复制后修改名称,访问不到项目 这是因为,你只是改了项目的名称,而没有改 下面是解决方法: 方法 1.右击你的项目,选择“properties”,在“type filter tex ...
- c# 轻量级 ORM 框架 之 Model解析 (四)
关于orm框架设计,还有必要说的或许就是Model解析了,也是重要的一个环节,在实现上还是相对比较简单的. Model解析,主要用到的技术是反射了,即:把类的属性与表的字段做映射. 把自己的设计及实现 ...
- MySQL Profile
1:查看MySQL当前版本是否支持profile mysql> SELECT @@HAVE_PROFILING; +------------------+ | @@HAVE_PROFILING ...
- UVA 253 (13.08.06)
Cube painting We have a machine for painting cubes. It is supplied withthree different colors: blu ...