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),每一次交换都有独特的汇率和手续费,问你存不存在一种换法使原来的钱更多. ...
随机推荐
- JavaScript,php文件上传简单实现
非ajax,非iframe,最原始使用file控件的文件上传,记录过程备忘.(同步,页面刷新) 实现目标,能够将文件上传到指定位置. 客户端用input的file控件: <form action ...
- [bzoj 1027][JSOI2007]合金(解析几何+最小环)
题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1027 分析: 首先因为一个合金的和为1,所以考虑2个材料合金能否合成一个需求合金的时候 ...
- linux网络命令
关键字 write wall last lastlog traceroute netstat mount 1.write 该命令可以给所有在线用户发送消息 示例: 接受消息用户:按回车可以退出 2.w ...
- js回掉页面后台代码-简单demo
后台代码: public partial class WebForm1 : System.Web.UI.Page, ICallbackEventHandler { protected void Pag ...
- Error: java.lang.UnsatisfiedLinkError: no ntvinv in java.library.path
Error Message When compiling or executing a Java application that uses the ArcObjects Java API, the ...
- IntellJ IDEA 所有快捷键
登录下面网站. http://www.jetbrains.com/idea/documentation/ 下载Keymap for Windows/Linux 后面的PDF文档.
- 在CentOS上装 ElasticSearch
参考官方文档:Install Elasticsearch with RPM ElasticSearch依赖Java,所以需要先安装Java: 到Oracle官网找到下载链接 http://www.or ...
- Java异常-一般异常和运行时异常的区别
Java提供了两类主要的异常:runtime exception和checked exception.checked 异常也就是我们经常遇到的IO异常,以及SQL异常都是这种异常.对于这种异常, JA ...
- svn版本控制方案:多分支并行开发,多环境自动部署
背景 keywords:svn,trunk,branch,jenkins,maven,merge 两地同时开发一个产品,目前线上有3个环境:测试环境.预发布环境.生产环境.目前系统部署采用jenkin ...
- 40.Android之新手指引界面学习
我们经常可以看到打开新App会有新手指引界面,类似蒙板效果今天来学习.原理其实很简单,设置一个透明Activity或者Dialog,然后修改其属性即可.由于实现比较简单,就贴一部分代码. 1.在And ...