Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 18899 | Accepted: 6743 |
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.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.Output
If Nick can increase his wealth, output YES, in other case output NO to the output file.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
解释一下基本题意,SB—hypo有s货币,价值为V,他想获得更多的货币。身为一个妻管严,该怎么办?╮(╯▽╰)╭,无奈。。。货币交换公式 (B货币) = (A货币总量-佣金)*汇率;
输入N,M,S,V;
下面M行,line 1 代表货币1 到 货币2 的 汇率、佣金,货币2 到 货币1 的 汇率、佣金
line 2 代表货币2 到 货币3 的 汇率、佣金,货币3 到 货币2 的 汇率、佣金
打印SB-hypo能否增加收入?YES/NO
PS: 没什么难度,就是贝尔曼的模板,敲上就差不多A了,但是WA了两次,以为是精度的问题,但是看了一下DISCUSS之后,发现dis[]的初始化不对,应该为0,而不INF,因为这个题是逆向使用贝尔曼算法,找的不是负环,而是可以使之钱数无限增加的正环。
#include#include #include #include #include const int INF = 1<<20; const int N = 110; const int Size = 9999; using namespace std; double mapp[N][N]; double dis[N],ANS; int n,m,s,l; double num; struct node{ int u,v; double hui,yong; }edge[Size]; void init() { l = 0;//若是找负环,dis[]应该初始化INF for(int i = 0;i dis[edge[j].u] + edge[j].w; 更新最短路 if(dis[edge[j].v] < (dis[edge[j].u] - edge[j].yong)* edge[j].hui) // 更新相对最长路 { dis[edge[j].v] = (dis[edge[j].u] - edge[j].yong)* edge[j].hui; flag = 1; } } if(flag==0)//更新完毕跳出 break; } for(int j = 0;j