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();
    }
    
  • 相关阅读:
    STL map
    HDU1372 Knight Moves BFS
    HDU1072 Nightmare BFS
    discuz论坛发帖添加字段
    gridview自定义button事件 ,无法触发 onrowcommand
    discuz 怎么开启评分!!!
    discuz学习网站收集
    discuz扩展工具集合
    童话世界整理“说说”
    asp.net中Literal与label的区别
  • 原文地址:https://www.cnblogs.com/mollnn/p/14648370.html
Copyright © 2011-2022 走看看