zoukankan      html  css  js  c++  java
  • poj 1860 Currency Exchange

    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. 

    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

    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

    题目大意:有多种汇币,汇币之间可以交换,这需要手续费,当你用100A币交换B币时,A到B的汇率是29.75,手续费是0.39,那么你可以得到(100 - 0.39) * 29.75 = 2963.3975 B币。问s币的金额经过交换最终得到的s币金额数能否增加。

    货币的交换是可以重复多次的,所以我们需要找出是否存在正权回路,且最后得到的s金额是增加的。

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <cstdlib>
     5 using namespace std;
     6 const int maxn=250;
     7 struct node
     8 {
     9     int a; //货币a
    10     int b; //货币b
    11     double rate;
    12     double com;//手续费
    13 } path[maxn];
    14 int n; //货币种数
    15 int m; //兑换点数量
    16 int s; //第几种货币
    17 double v; //持有s种货币的本金
    18 int index;
    19 double val[maxn]; //s到各边的权值
    20 bool bellman()
    21 {
    22     bool flag;
    23     for(int i=1; i<=n; i++)
    24         val[i]=-1.0;
    25     val[s]=v;
    26     for(int i=1; i<=n; i++)
    27     {
    28         flag=false;
    29         for(int j=1; j<index; j++)
    30         {
    31             if(val[path[j].b]<(val[path[j].a]-path[j].com)*path[j].rate)
    32             {
    33                 val[path[j].b]=(val[path[j].a]-path[j].com)*path[j].rate;
    34                 flag=true;
    35             }
    36         }
    37         if(!flag)
    38             break;
    39     }
    40     return flag;
    41 }
    42 int main()
    43 {
    44     int a,b;
    45     double a1,a2,b1,b2;
    46     scanf("%d%d%d%lf",&n,&m,&s,&v);
    47     index=1;
    48     for(int i=1; i<=m; i++)
    49     {
    50         scanf("%d%d%lf%lf%lf%lf",&a,&b,&a1,&b1,&a2,&b2);
    51         path[index].a=a,path[index].b=b;
    52         path[index].rate=a1,path[index].com=b1;
    53         index++;
    54         path[index].a=b,path[index].b=a;
    55         path[index].rate=a2,path[index].com=b2;
    56         index++;
    57     }
    58     if(bellman())
    59         printf("YES
    ");
    60     else
    61         printf("NO
    ");
    62     return 0;
    63 }
    View Code
  • 相关阅读:
    jpa命名规则 jpa使用sql语句 @Query
    spring data jpa 查询No property ... found for...Did you mean '...'?
    maven配置sqlServer的依赖
    SpringBoot 使用Swagger2打造在线接口文档(附汉化教程)
    本地git库gitlab库链接服务器库 idea git 配置 gitlab 配置 git生成ssh公钥
    连接sqlServer数据库&jpa调用存储过程Java获取存储过程返回的多个结果集JAVA调用sqlserver存储过程的实现(返回多个结果集的实现)jdbc多结果集(getMoreResults)
    Springmvc的handler method参数绑定常用的注解
    Java map 详解
    Http请求中Content-Type讲解以及在Spring MVC注解中produce和consumes配置详解
    @Controller和@RestController的区别
  • 原文地址:https://www.cnblogs.com/cxbky/p/4904601.html
Copyright © 2011-2022 走看看