題目鏈接:http://poj.org/problem?id=1860
Currency Exchange Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 18609 Accepted: 6619Description
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
Northeastern Europe 2001, Northern Subregion 這個題目又是貨幣的兌換,覺得用belloman-ford算法處理很好。。這個題目是最短路的變形。。如果第二次松弛的時候還能出現松弛,則說明有環,則可以說明可以鑽錢。。。。
代碼如下:
#include#include #define maxn 300 struct edge { int u,v; double r,c; }e[maxn]; int n,m,s; int pos=0; double v; double d[maxn]; int bellman_ford() { int x,y; int k,i; double rate,com; memset(d,0,sizeof(d)); d[s]=v; for(k=1;k