zoukankan      html  css  js  c++  java
  • Educational Codeforces Round 42 (Rated for Div. 2) D

    这道题我可以直接模拟
    理由是一个数*2的过程中最多30次左右
    2^31 = 2e9
    所以我可以从小的书开始模拟这个过程

    #include <iostream>
    #include <cstring>
    #include <cstdio>
    #include <algorithm>
    #include <map>
    #include <vector>
    #include <set>
    typedef long long ll;
    
    const int N = 150005;
    const int INF = 0x3f3f3f3f;
    int A[N];
    std::map<ll, std::set<int> > mp;
    std::map<int, ll> ans;
    int main() {
        int n;
        while(~scanf("%d", &n)) {
            mp.clear();
            ans.clear();
            for(int i = 0; i < n; ++i) scanf("%d", &A[i]);
            for(int i = 0; i < n; ++i) {
                mp[A[i]].insert(i);
            }
    
            for(auto i = mp.begin(); i != mp.end(); ++i) {
                std::set<int> &target = i->second;
                int cnt = 0; int last;
                for(auto j = target.begin(); j != target.end(); ++j) {
                    cnt ++;
                    if(cnt % 2 == 0) {
                        mp[i->first * 2].insert(*j);
                    }
                    last = *j;
                }
                if(cnt % 2) ans[last] = i->first;
            }
    
            printf("%d
    ", (int)ans.size());
            for(auto i = ans.begin(); i != ans.end(); ++i) {
                printf("%lld ", i->second);
            }
            printf("
    ");
        }
        return 0;
    }
    
  • 相关阅读:
    好玩的spring boot banner 图
    数据结构和算法二(数组)
    数据结构与算法三(链表)
    数据结构和算法一(基础知识)
    jenkins 部署node应用
    Docker-compose 安装Jenkins
    Docker 网络模式
    exe4j 转jar
    c#索引器的简单用法
    Adapter模式
  • 原文地址:https://www.cnblogs.com/Basasuya/p/8850334.html
Copyright © 2011-2022 走看看