poj 1860 Currency Exchange
来源:互联网 发布:电脑怎么摆脱网络控制 编辑:程序博客网 时间:2024/04/30 05:15
Currency Exchange
Time Limit: 1000MS Memory Limit: 30000KTotal Submissions: 26483 Accepted: 9791
Description
Several currency exchange points are working in our city. Let us suppose that each point specializes in two particular currencies and performs exchange operations only with these currencies. There can be several points specializing in the same pair of currencies. Each point has its own exchange rates, exchange rate of A to B is the quantity of B you get for 1A. Also each exchange point has some commission, the sum you have to pay for your exchange operation. Commission is always collected in source currency.
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.
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
The first line of the input contains four numbers: N - the number of currencies, M - the number of exchange points, S - the number of currency Nick has and V - the quantity of currency units he has. The following M lines contain 6 numbers each - the description of the corresponding exchange point - in specified above order. Numbers are separated by one or more spaces. 1<=S<=N<=100, 1<=M<=100, V is real number, 0<=V<=103.
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.
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
If Nick can increase his wealth, output YES, in other case output NO to the output file.
Sample Input
3 2 1 20.01 2 1.00 1.00 1.00 1.002 3 1.10 1.00 1.10 1.00
Sample Output
YES
这个题就是找正环问题
一定要记住换钱的顺序
#include <stdio.h>#include <iostream>#include <algorithm>#include <string.h>#define MAX 0x3f3f3f3fusing namespace std;struct node{ int z1,z2; double c1,c2,d1,d2;}a[10002];double q[10002];int main(){ int n,m,i,j; int z; double h; while(~scanf("%d %d %d %lf",&n,&m,&z,&h)) { for(i = 1;i <= m; i++) { scanf("%d %d %lf %lf %lf %lf",&a[i].z1,&a[i].z2,&a[i].c1,&a[i].c2,&a[i].d1,&a[i].d2); } for(i = 1;i <= n; i++) { q[i] = 0; } q[z] = h; int ok = 0; for(j = 1;j < n; j++) { for(i = 1;i <= m; i++) { if(q[a[i].z1] < (q[a[i].z2]-a[i].d2)*a[i].d1) //这一行是程序的关键(换钱如何换) { q[a[i].z1] = (q[a[i].z2]-a[i].d2)*a[i].d1; } if(q[a[i].z2] < (q[a[i].z1]-a[i].c2)*a[i].c1) { q[a[i].z2] = (q[a[i].z1]-a[i].c2)*a[i].c1; } } } for(i = 1;i <= m; i++) //如果第n次交换还有所改变就有正环 { if(q[a[i].z1] < (q[a[i].z2]-a[i].d2)*a[i].d1) { ok = 1; break; } if(q[a[i].z2] < (q[a[i].z1]-a[i].c2)*a[i].c1) { ok = 1; break; } } if(ok) { printf("YES\n"); } else { printf("NO\n"); } }}
代码菜鸟,如有错误,请多包涵!!!
0 0
- POJ 1860 Currency Exchange
- poj 1860 Currency Exchange
- POJ 1860 Currency Exchange
- Poj 1860 Currency Exchange
- POJ 1860 Currency Exchange
- poj 1860 Currency Exchange
- POJ 1860 Currency Exchange
- poj 1860 Currency Exchange
- POJ 1860 Currency Exchange
- POJ 1860 Currency Exchange
- POJ 1860 Currency Exchange
- poj 1860 Currency Exchange
- POJ 1860 Currency Exchange
- poj 1860 Currency Exchange
- POJ-1860-Currency Exchange
- POJ 1860 Currency Exchange
- poj 1860 Currency Exchange
- POJ 1860 Currency Exchange
- HDOJ 1280 前M大的数
- 1027. 打印沙漏(20)--做题记录
- Java 反射的详解
- 大数据IMF传奇行动绝密课程第21课:从Spark架构中透视Job
- RMQ(模板)(改)
- poj 1860 Currency Exchange
- HDU Problem 1875 畅通工程再续 【最小生成树Prim】
- iOS开发中视图相关的小笔记:push、modal、popover、replace、custom
- unity翻牌小游戏(初学者)
- TEST
- sap 增强
- HDOJ 1862 EXCEL排序
- ztree 懒加载
- Unity3D 学习日志之一 Survival shooter P3