zoukankan      html  css  js  c++  java
  • D

    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 R AB, C AB, R BA and C BA - 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<=10 3
    For each point exchange rates and commissions are real, given with at most two digits after the decimal point, 10 -2<=rate<=10 2, 0<=commission<=10 2
    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 10 4

    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

    题目意思:有N种货币,M种有多种汇币,汇币之间可以交换,这需要手续费,当你用100A币交换B币时,A到B的汇率是29.75,手续费是0.39,
    那么你可以得到(100 - 0.39) * 29.75 = 2963.3975 B币。问s币的金额经过交换最终得到的s币金额数能否增加
    解题思路:货币的交换是可以重复多次的,所以我们需要找出是否存在正权回路,且最后得到的s金额是增加的,
    最短路的变形,最长路;


     1 #include<iostream>
     2 #include <string.h>
     3 #include <math.h>
     4 #include <stdio.h>
     5 using namespace std;
     6 
     7 const int MAX = 300 + 100;
     8 
     9 
    10 struct S
    11 {
    12     int a,b;
    13     double rate;
    14     double comm;
    15 };
    16 
    17 S Map[MAX];
    18 int N,n,my;
    19 double mynum;
    20 int visit[MAX];
    21 double dist[MAX];
    22 int add ;
    23 
    24 bool B()
    25 {
    26     memset(dist,0,sizeof(dist));
    27     dist[my] = mynum;
    28 
    29     bool flag;
    30     for(int i =1;i <=N;i++)
    31     {
    32         flag = false;
    33         for(int j = 0;j <add;j++)
    34             if( dist[Map[j].b] <((dist[Map[j].a] - Map[j].comm)*Map[j].rate) )
    35             {
    36                 dist[Map[j].b] =((dist[Map[j].a] - Map[j].comm)*Map[j].rate);
    37                 flag = true;
    38             }
    39         if(!flag)
    40             break;
    41     }
    42 
    43     for(int j =0;j <add;j++)
    44         if(dist[Map[j].b] <((dist[Map[j].a] - Map[j].comm)*Map[j].rate))
    45             return true;
    46     return false;
    47 
    48 }
    49 
    50 int main()
    51 {
    52 
    53     cin>>N>>n>>my>>mynum;
    54 
    55     add = 0;
    56     for(int i =1;i <= n;i++)
    57     {
    58         int x,y;
    59         double a,b,c,d;
    60         cin>>x>>y>>a>>b>>c>>d;
    61         Map[add].a = x;
    62         Map[add].b = y;
    63         Map[add].rate = a;
    64         Map[add++].comm = b;
    65         Map[add].a = y;
    66         Map[add].b = x;
    67         Map[add].rate = c;
    68         Map[add++].comm = d;
    69     }
    70 
    71     if( B() )
    72         cout<<"YES"<<endl;
    73     else
    74         cout<<"NO"<<endl;
    75 
    76 
    77     return 0;
    78 }



  • 相关阅读:
    第一次结对编程作业
    第一次个人编程作业
    软工实践作业(一)
    通往SDN之路:可编程网络的思想史
    week9:Security: Web Security
    week8:Security: Encrypting and Signing
    week7:Technology: Application Protocols
    week6:Technology: Transport Control Protocol (TCP)
    10.消除左递归
    9.DFA最小化,语法分析初步
  • 原文地址:https://www.cnblogs.com/a2985812043/p/7304877.html
Copyright © 2011-2022 走看看