zoukankan      html  css  js  c++  java
  • [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;
    }
  • 相关阅读:
    brctl 使用说明
    Flash文件系统介绍和平台采用squashfs+ubifs原因
    xargs
    svn的常用命令
    shell中的if用法
    shell中单双引号
    删除文件中的 ^M 字符
    博客园添加live2d看板娘
    IOS 自定义转场动画
    rails
  • 原文地址:https://www.cnblogs.com/zeolim/p/12270460.html
Copyright © 2011-2022 走看看