Currency Exchange(Bellman-ford)
| Time Limit: 1000MS | Memory Limit: 30000K | |
| Total Submissions: 21349 | Accepted: 7653 | 
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 RAB, CAB, RBA and CBA - 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<=102, 0<=commission<=102.
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 104.
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
Source
#include<stdio.h>
struct edge
{
int u , v ;
double r , c ;
}e[];
int n , m , s ;
double cap ;
int cnt = ;
double d[] ; bool Bellman_ford()
{
for (int i = ; i <= n ; i++)
d[i] = ;
d[s] = cap ;
bool flag ;
for (int i = ; i <= n ; i++) {
flag = ;
for (int j = ; j < cnt ; j++) {
if (d[e[j].v] < ( d[e[j].u] - e[j].c ) * e[j].r ) {
flag = ;
d[e[j].v] = ( d[e[j].u] - e[j].c ) * e[j].r ;
}
}
if (flag)
return false ;
} return true ;
} int main ()
{
freopen ("a.txt" , "r" , stdin) ;
scanf ("%d%d%d%lf" , &n , &m , &s , &cap) ;
while (m--) {
scanf ("%d%d%lf%lf" , &e[cnt].u , &e[cnt].v , &e[cnt].r , &e[cnt].c) ;
cnt++;
e[cnt].u = e[cnt - ].v , e[cnt].v = e[cnt - ].u ;
scanf ("%lf%lf" , &e[cnt].r , &e[cnt].c) ;
cnt++;
}
/*for (int i = 0 ; i < cnt ; i++)
printf ("u = %d , v = %d , e[i].r = %.2f , e[i].c = %.2f\n" , e[i].u , e[i].v , e[i].r , e[i].c) ;*/
if (Bellman_ford())
puts ("YES") ;
else
puts ("NO") ; return ;
}
Currency Exchange(Bellman-ford)的更多相关文章
- 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 (最短路)
		
Currency Exchange Time Limit : 2000/1000ms (Java/Other) Memory Limit : 60000/30000K (Java/Other) T ...
 - POJ 1860	 Currency Exchange (bellman-ford判负环)
		
Currency Exchange 题目链接: http://acm.hust.edu.cn/vjudge/contest/122685#problem/E Description Several c ...
 - POJ 2240 Arbitrage   (Bellman Ford判正环)
		
Arbitrage Time Limit: 1000MS Memory Limit: 65536K Total Submissions:27167 Accepted: 11440 Descri ...
 - Currency Exchange(最短路)
		
poj—— 1860 Currency Exchange Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 29851 Ac ...
 - POJ1860 Currency Exchange(bellman-ford)
		
链接:http://poj.org/problem?id=1860 Currency Exchange Description Several currency exchange points are ...
 - POJ 1860 Currency Exchange(如何Bellman-Ford算法判断图中是否存在正环)
		
题目链接: https://cn.vjudge.net/problem/POJ-1860 Several currency exchange points are working in our cit ...
 - Currency Exchange(SPFA判负环)
		
Several currency exchange points are working in our city. Let us suppose that each point specializes ...
 - poj1860 兑换货币(bellman ford判断正环)
		
传送门:点击打开链接 题目大意:一个城市有n种货币,m个货币交换点,你有v的钱,每个交换点只能交换两种货币,(A换B或者B换A),每一次交换都有独特的汇率和手续费,问你存不存在一种换法使原来的钱更多. ...
 
随机推荐
- 通俗易懂------this指向
			
因为JavaScript 中this 是在运行期进行绑定的,因此JavaScript 中this 关键字具备多重含义. 具体在实际应用中,this的指向大致可以分为下面4种. 作为对象的方法调用 ...
 - Mac无法找到摄像头问题解决
			
facetime显示“未检测到摄像头”之类的,重启后可能摄像头有工作正常了,摄像头不稳定 重置 NVRAM后恢复正常,据说机器卡的时候,此法也可以使用. https://support.apple.c ...
 - DOM(六)事件类型
			
对于用户事件类型而言,最常用的是鼠标.键盘.浏览器. 1.鼠标事件: 鼠标的事件都频繁使用,下面例子就测试各种鼠标事件 <script language="javascript&quo ...
 - 第二章:Javascript词法结构
			
编程语言的词法结构是一套基础性的规则,用来描述你如何编写这门语言.作为语法的基础,它规定了变量名是怎么样的,如何写注释,以及语句之间是如何区分的.本节用很短的篇幅来介绍javascript的词法结构. ...
 - PHP中文处理 中文字符串截取(mb_substr)和获取中文字符串字数
			
一.中文截取:mb_substr() mb_substr( $str, $start, $length, $encoding ) $str,需要截断的字符串 $start,截断开始处,起始处为0 $l ...
 - WPF小知识,MessageBox的多种用法
			
我们在程序中经常会用到MessageBox. 现将其常见用法总结如下: 1.MessageBox.Show("Hello~~~~"); 最简单的,只显示提示信息. 2.Messag ...
 - Solr -- 实时搜索
			
在solr中,实时搜索有3种方案 ①soft commit,这其实是近实时搜索,不能完全实时. ②RealTimeGet,这是实时,但只支持根据文档ID的查询. ③和第一种类似,只是触发softcom ...
 - Teradata(不同date输出要求;表类型)
			
1. 需要某种特定形式的date 类型export 到文件中,例如 YYYYMMDD/ YYYY-MM-DD 这时候不一定非要用date 类型,可以转换为varchar 类型! CAST(CAST ( ...
 - BZOJ-1477    青蛙的约会     拓展欧几里德
			
充权限之前做的...才来交 1477: 青蛙的约会 Time Limit: 2 Sec Memory Limit: 64 MB Submit: 369 Solved: 233 [Submit][Sta ...
 - BZOJ1452 [JSOI2009]Count
			
Description Input Output Sample Input Sample Output 1 2 HINT 正解:二维树状数组 解题报告: 这是一道送肉题.二维树状数组直接维护每种颜色的 ...