zoukankan      html  css  js  c++  java
  • E

    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
    #include <iostream>
    #include <vector>
    #include <algorithm>
    #include <string>
    #include <set>
    #include <queue>
    #include <map>
    #include <sstream>
    #include <cstdio>
    #include <cstring>
    #include <numeric>
    #include <cmath>
    #include <iomanip>
    #include <deque>
    #include <bitset>
    //#include <unordered_set>
    //#include <unordered_map>
    //#include <bits/stdc++.h>
    //#include <xfunctional>
    #define ll              long long
    #define PII              pair<int, int>
    #define rep(i,a,b)    for(ll  i=a;i<b;i++)
    #define dec(i,a,b)    for(ll  i=a;i>=b;i--)
    #define pb              push_back
    #define mp              make_pair
    using namespace std;
    int dir[5][2] = { { 0,1 } ,{ 0,-1 },{ 1,0 },{ -1,0 } ,{ 0,0 } };
    const long long INF = 0x7f7f7f7f7f7f7f7f;
    const int inf = 0x3f3f3f3f;
    const double pi = 3.14159265358979;
    const int mod = 1e9 + 7;
    const int N = 105;
    //if(x<0 || x>=r || y<0 || y>=c)
    //1000000000000000000
    
    inline ll read()
    {
        ll x = 0; bool f = true; char c = getchar();
        while (c < '0' || c > '9') { if (c == '-') f = false; c = getchar(); }
        while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
        return f ? x : -x;
    }
    
    vector<vector<double>> rate(N, vector<double>(N,0)), cost(N, vector<double>(N,0));
    vector<double> dis(N, 0);
    vector<bool> inq(N);
    int n, m, s;
    double v;
    
    bool spfa(int start)
    {
        vector<bool> vis(N, false);
        dis[start] = v;
        queue<int> que;
        que.push(start);
        vis[start] = 1;
        while (!que.empty())
        {
            int front = que.front();a
            que.pop();
            vis[front] = 0;
            for (int i = 0; i <= n; i++)
            {
                if (dis[i] < (dis[front] - cost[front][i])*rate[front][i])
                {
                    dis[i] = (dis[front] - cost[front][i])*rate[front][i];
                    if (dis[start] > v)
                        return true;
                    if (!vis[i])
                    {
                        que.push(i);
                        vis[i] = 1;
                    }
                }
            }
        }
        return false;
    }
    
    int main()
    {
        cin >> n >> m >> s >> v;
        rep(i, 0, m)
        {
            int a, b;
            cin >> a >> b;
            cin >> rate[a][b] >> cost[a][b] >> rate[b][a] >> cost[b][a];
        }
        rep(i, 0, n)
        {
            rate[i][i] = 1;
        }
        if (spfa(s))
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
        return 0;
    }
  • 相关阅读:
    Docker 私有仓库搭建
    事务提交与不同数据库的自增方式
    多环境切换&&注解方式&&增删改返回值问题
    查询缓存&&逆向工程
    Mybatis整合Log4j、延迟加载
    关联查询
    MyBatis实现动态SQL
    输出参数resultType
    MyBatis调用存储过程执行CRUD
    两种取值符号的异同
  • 原文地址:https://www.cnblogs.com/dealer/p/12692510.html
Copyright © 2011-2022 走看看