zoukankan      html  css  js  c++  java
  • [CF1490E] Accidental Victory

    [CF1490E] Accidental Victory

    Description

    每个队伍初始时有一些代币,比赛每一轮随机挑两个代币数不为 0 的队伍,然后代币多的队伍获胜,代币少的队伍把代币全部给代币多的(代币数量相同则随机),直到最后只有一个队伍有代币,这个队伍获胜。求哪些队伍有可能获胜。

    Solution

    对于一个队伍,如果他消灭掉所有小于等于他的队伍,此时的代币数量不小于最大值,那么就能赢

    #include <bits/stdc++.h>
    using namespace std;
    
    #define int long long
    
    void solve()
    {
        int n;
        cin >> n;
    
        vector<pair<int, int>> a(n);
        for (int i = 0; i < n; i++)
        {
            int x, y;
            cin >> x;
            y = i + 1;
            a[i] = {x, y};
        }
    
        sort(a.begin(), a.end());
    
        int sum = 0;
        int mx = a[n - 1].first;
        vector<int> b(n);
        vector<int> ans;
        int j = 0;
        for (int i = 0; i < n; i++)
        {
            if (j <= i)
                ++j, sum += a[i].first;
            while (j < n && sum >= a[j].first)
                sum += a[j].first, ++j;
            if (sum >= mx)
                ans.push_back(a[i].second);
        }
        sort(ans.begin(), ans.end());
        cout << ans.size() << endl;
        for (int i = 0; i < ans.size(); i++)
            cout << ans[i] << " ";
        cout << endl;
    }
    
    signed main()
    {
        ios::sync_with_stdio(false);
    
        int t;
        cin >> t;
        while (t--)
        {
            solve();
        }
    }
    
  • 相关阅读:
    opencv3.2.0形态学滤波之腐蚀
    Ubuntu下卸载QT5.7.1再重装
    opencv3.2.0形态学滤波之膨胀
    Direct3D中的绘制
    绘制流水线
    初始化Direct3D
    VS2012添加对DirectX SDK中需要文件的引用
    ASCII,Unicode 和通用方式
    对话框访问的7种方式【孙鑫老师教程】
    函数指针
  • 原文地址:https://www.cnblogs.com/mollnn/p/14433150.html
Copyright © 2011-2022 走看看