POJ 1860 Currency Exchange: Shortest Way Bellman-ford

Source: Internet
Author: User
Tags bool printf

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
            , &AMP;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; }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.