• [ICPC2016上海E] Bet


    [ICPC2016上海E] Bet - 贪心

    Description

    给你每个队的赔率,你可以任意分配金额,问最多投多少个队使得只要有一个队赢了,就能赚钱。

    Solution

    预处理投每个队至少多少钱使得如果该队赢刚好回本,然后贪心选择即可,恶心的地方在于卡精度

    #include <bits/stdc++.h>
    using namespace std;
    
    #define int long long
    
    #define double long double
    
    const int N = 1e2 + 5;
    const double eps = 1e-36;
    
    int caseid = 0;
    int n;
    double p[N];
    
    void solve()
    {
        ++caseid;
        cin >> n;
        for (int i = 1; i <= n; i++)
        {
            double a, b;
            string str;
            cin >> str;
            for (int i = 0; i < str.length(); i++)
                if (str[i] == ':')
                    str[i] = ' ';
            stringstream ss(str);
            ss >> a >> b;
            p[i] = a / (a + b);
        }
        cout << "Case #" << caseid << ": ";
        if (n == 1)
        {
            cout << 1 << endl;
            return;
        }
        sort(p + 1, p + n + 1);
        double res = 1;
        int ans = 0;
        for (int i = 1; i <= n; i++)
        {
            double cost = p[i];
            if (res - cost > eps)
            {
                res -= cost;
                ans++;
            }
            else
                break;
        }
        cout << ans << endl;
    }
    
    signed main()
    {
        ios::sync_with_stdio(false);
        int t;
        cin >> t;
        while (t--)
            solve();
    }
    
  • 相关阅读:
    vue子组件获取父组件方法
    css hack
    【Educational Codeforces Round 87 (Rated for Div. 2)】前4题
    【某次ks】20200512
    NoI Online 2反思
    RMQ&LCA
    杂谈
    高手训练矩乘T3
    0118ACM自闭赛
    网络流初步学习笔记
  • 原文地址:https://www.cnblogs.com/mollnn/p/14667829.html
Copyright © 2020-2023  润新知