zoukankan      html  css  js  c++  java
  • [CCPC2020绵阳L] Lottery

    [CCPC2020绵阳L] Lottery

    Description

    给你 n 组 a x(每个 a 都相同),代表有 x 个 2 ^ a,问用这些数字最多组成多少种不同的数字。

    Solution

    相同的元素最多保留两个,多的变成大的

    非连续的不会相互影响(因为和不够),所以相互独立

    每段连续的以最小的为单位求和再加一,乘起来就是答案

    #include <bits/stdc++.h>
    using namespace std;
    
    #define int long long
    
    const int mod = 1e9 + 7;
    
    int cid = 0;
    
    void solve()
    {
        int n;
        cin >> n;
        map<int, int> src;
        while (n--)
        {
            int a, x;
            cin >> a >> x;
            src[a] += x;
        }
    
        for (auto &[x, y] : src)
        {
            if (y > 2)
            {
                src[x + 1] += (y - 1) / 2;
                y -= (y - 1) / 2 * 2;
            }
        }
    
        vector<pair<int, int>> vec;
        for (auto [x, y] : src)
            if (y > 0)
                vec.push_back({x, y});
    
        int m = vec.size();
        int l = 0, r;
        int ans = 1;
        while (l < m)
        {
            int sum = 1 + vec[l].second, bas = 1;
            r = l + 1;
            while (r < m && vec[r].first == vec[r - 1].first + 1)
            {
                bas *= 2;
                sum += bas * vec[r].second;
                bas %= mod;
                sum %= mod;
                ++r;
            }
            ans *= sum;
            ans %= mod;
            l = r;
        }
        ++cid;
        cout << "Case #" << cid << ": ";
        cout << ans << endl;
    }
    
    signed main()
    {
        ios::sync_with_stdio(false);
    
        int t;
        cin >> t;
        while (t--)
            solve();
    }
    
  • 相关阅读:
    C++ 纸牌 今日头条面试题
    c++ 病句 今日头条面试题
    C++ 球迷 今日头条面试题
    C++ 活动安排
    C++ 弗洛伊德算法
    填坑 bzoj3337
    bzoj3884 上帝与集合的正确用法
    人参中第一次膜你退货
    洛谷P2216 [HAOI2007]理想的正方形
    洛谷 P1099 树网的核+P2491 [SDOI2011]消防
  • 原文地址:https://www.cnblogs.com/mollnn/p/14648370.html
Copyright © 2011-2022 走看看