Currency exchange:http://poj.org/problem?id=1860
The effect: There are a variety of currencies, can be exchanged between, but the need for fees, that is, both exchange rates and handling charges. Ask if you can make money after the exchange.
Train of thought: Bellman_ford, because the request is the longest road, so the relaxation condition changes just fine.
Tips:
3 2 1 20.0
The number of currency exchange points the protagonist has the amount of money the protagonist has the value of the Currency 1 2 1.00 1.00 1.00 1.00
Currency 1 and Currency 2 Exchange, 1 and 2 of the exchange rate is 1.00,1 for 2 of the handling fee is 1.00,2 and 1 exchange rate is 1.00,2 for 1 of the handling fee is 1.00. 2 3 1.10 1.00 1.10 1.00
Currency 1 and Currency 2 Exchange, 1 and 2 of the exchange rate is 1.10,1 for 2 of the handling fee is 1.00,2 and 1 exchange rate is 1.10,2 for 1 of the handling fee is 1.00.
More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/
#include <stdio.h> #include <iostream> #include <map> #include <stack> #include <string.h
> #define INF 0x3f3f3f3f using namespace std;
int N, m, s;
Double V;
Double dis[110];
int t;
struct node {int x, y;
Double R, C;
} map[210];
BOOL Bellman_ford () {memset (dis, 0, sizeof (DIS));
Dis[s] = v;
for (int i = 1; I <= n-1 i++) {BOOL flag = false;
for (int j = 0; J < T; J +) {if (Dis[map[j].y] < (DIS[MAP[J].X]-MAP[J].C) *MAP[J].R) {
DIS[MAP[J].Y] = (dis[map[j].x]-map[j].c) *MAP[J].R;
Flag = true;
} if (!flag) {break;
for (int i = 0; i < T; i++) {if (Dis[map[i].y] < (DIS[MAP[I].X]-MAP[I].C) *MAP[I].R) {
return true;
return false;
} void Solve () {int A, B;
Double Rab, Rba, Cab, Cba; while (~SCANF ("%d%d%d%lf", &n, &m, &s, &v)) {t = 0; for (int i = 0; i < m i++) {scanf ("%d%d%lf%lf%lf%lf", &a, &b, &rab, &cab, &rba
, &CBA);
map[t].x = A;
Map[t].y = b;
MAP[T].R = Rab;
MAP[T++].C = Cab;
map[t].x = b;
Map[t].y = A;
MAP[T].R = Rba;
MAP[T++].C = Cba;
} if (Bellman_ford ()) {printf ("yes\n");
else {printf ("no\n");
int main () {Solve ()}}
return 0; }