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 ...
随机推荐
- 利用HTML5开发Android(7)---HTML5本地存储之Database Storage
在上一篇<HTML5本地存储之Web Storage篇>中,简单介绍了如何利用localStorage实现本地存储:实际上,除了sessionStorage和localStorage外,H ...
- OC: Block回调的使用demo
Block 的用法 对于类的继承问题,子类在实现的时候,一般是自下而上,先看看下面的实现没有,没实现就向上找方法去实现. // // main.m #import <Foundation/Fou ...
- JavaScript设计模式 -- 读书笔记
JavaScript设计模式 一. 设计模式 一个模式就是一个可重用的方案: 有效的解决方法.易重用.善于表达该解决方案: 未通过"模式特性"测试的模式称为模式原型: 三规则:适用 ...
- LNMP环境下压力测试时的主要调试参数
LNMP环境下压力测试时的主要调试参数: 进行HTTP的压力测试时,很多时候会遇到很小的并发数,服务器就会出现不响应,或者连接超时,一般导致的原因有如下几点: 一.Nginx主要调试参数 主模块参数: ...
- NGINX源代码剖析 之 CPU绑定(CPU亲和性)
作者:邹祁峰 邮箱:Qifeng.zou.job@gmail.com 博客:http://blog.csdn.net/qifengzou 日期:2014.06.12 18:44 转载请注明来自&quo ...
- Azure编程笔记(1):序列化复杂类型的TableEntity字段
内容提要 在使用MicrosoftAzure的CloudTable存储数据时,我们先要把数据定义成TableEntity的子类.假设TableEntity中包括复杂类型(比方容器类型如List等.或者 ...
- [Angular2 Form] Style Validation in Angular 2 Forms
Inputs using Angular 2’s ngModel automatically apply style classes of .ng-validand .ng-invalid each ...
- 如何在 iOS 8 中使用 Swift 实现本地通知(上)
当你的应用在后台运行时,可以简单地使用本地通知把信息呈现给用户.它可以允许你显示 提醒.播放提示音和数字角标(badge).本地通知可以被以下的事件触发:计划好的时间点或者用户进入和离开某个地理区域. ...
- Linux 可执行文件 ELF结构 及程序载入执行
Linux下ELF文件类型分为以下几种: 1.可重定位文件,比如SimpleSection.o: 2.可运行文件,比如/bin/bash. 3.共享目标文件,比如/lib/libc.so. 在Linu ...
- OC和JS之间的交互
OC和JS之间的交互 目录 对OC和JS之间交互的理解 JS调用OC OC调用JS 对OC和JS之间交互的理解 JS调用OC JS文件 function sendCommand(cmd,param){ ...