• [STL] [PQ] [NYNUOJ] 1152 No game no life


    用STL优先队列进行模拟

    但是求小根堆

    好像是

    priority_queue <ll, vector<ll>, greater<> > PQ;

    比较麻烦

    直接默认PQ塞负数也可以解决

    //#pragma GCC optimize(2)
    #include <cstdio>
    #include <iostream>
    #include <cstdlib>
    #include <cmath>
    #include <cctype>
    #include <string>
    #include <cstring>
    #include <algorithm>
    #include <stack>
    #include <queue>
    #include <set>
    #include <map>
    #include <ctime>
    #include <vector>
    #include <fstream>
    #include <list>
    #include <iomanip>
    #include <numeric>
    using namespace std;
    typedef long long ll;
     
    const int MAXN = 1e6 + 10;
     
    ll ans;
     
    priority_queue <ll> PQ;
     
    int main()
    {
        //ios::sync_with_stdio(false);
     
        //cin.tie(0);     cout.tie(0);
     
        ll n, m, tmp, ta, tb;
     
        cin>>n>>m;
     
        for(int i = 0; i < n; i++)
        {
            cin>>tmp;
     
            PQ.push(-tmp);
        }
     
        while(PQ.size() != 1)
        {
            ta = PQ.top();
     
            PQ.pop();
     
            tb = PQ.top();
     
            PQ.pop();
     
            if(ta == tb)
            {
                PQ.push(2 * ta);
            }
     
            else
            {
                PQ.push(2 * max(ta, tb));
            }
        }
     
        ans = -PQ.top();
     
        cout<<ans<<endl;
     
        return 0;
    }
  • 相关阅读:
    详解Codis安装与部署
    停车场地图开发
    dlib换脸
    海康相机官网硬触发设置
    python操作数据库
    心率和血氧测量
    音乐模块
    flask网页显示图片
    树莓派识别二维码
    树莓派python获取自身IP
  • 原文地址:https://www.cnblogs.com/zeolim/p/12270460.html
Copyright © 2020-2023  润新知