zoukankan      html  css  js  c++  java
  • codeforces962D

    div2D

    sol:

    每次找到两个最小的数,如果相同则塞回去一个,不同则存下小的作为答案

    复习一波优先队列

    #include <bits/stdc++.h>
    using namespace std;
    #define int long long
    typedef int ll;
    inline ll read()
    {
        ll s=0; bool f=0; char ch=' ';
        while(!isdigit(ch)) {f|=(ch=='-'); ch=getchar();}
        while(isdigit(ch)) {s=(s<<3)+(s<<1)+(ch^48); ch=getchar();}
        return (f)?(-s):(s);
    }
    #define R(x) x=read()
    inline void write(ll x)
    {
        if(x<0) {putchar('-'); x=-x;}
        if(x<10) {putchar(x+'0'); return;}
        write(x/10); putchar((x%10)+'0');
    }
    #define W(x) write(x),putchar(' ')
    #define Wl(x) write(x),putchar('
    ')
    const int N=200005;
    int n,a[N];
    struct node
    {
        int v,id;
        bool operator<(const node &tmp) const
        {
            return (tmp.v==v)?tmp.id<id:tmp.v<v;
        }
    }lwj[N];
    priority_queue<node>que,wwx;
    inline bool cmp(node pp,node qq)
    {
        return pp.id<qq.id;
    }
    signed main()
    {
    //    freopen("codeforces.in","r",stdin);
        int i,cnt=0;
        R(n);
        for(i=1;i<=n;i++) R(a[i]);
        if(n==1)
        {
            Wl(1);
            Wl(a[1]);
            return 0;
        }
        for(i=1;i<=n;i++) que.push((node){a[i],i});
    //    for(i=1;i<=n;i++)
    //    {
    //        node tmp=que.top();
    //        cout<<tmp.id<<" "<<tmp.v<<endl;
    //        que.pop();
    //    }
        node wn,wq;
        while(que.size()>1)
        {
            wn=que.top();
            que.pop();
            wq=que.top();
            que.pop();
    //        cout<<wn.v<<" "<<wn.id<<" "<<wq.v<<" "<<wq.id<<endl;
            if(wn.v^wq.v)
            {
                wwx.push(wn);
                que.push(wq);
            }
            else
            {
                que.push((node){wn.v*2,wq.id});
            }
        }
        wwx.push(que.top());
        Wl((int)wwx.size());
        while(wwx.size()>0)
        {
            lwj[++cnt]=wwx.top();
            wwx.pop();
        }
        sort(lwj+1,lwj+cnt+1,cmp);
        for(i=1;i<=cnt;i++) W(lwj[i].v);
        return 0;
    }
    View Code
    河田は河田、赤木は赤木……。 私は誰ですか。教えてください、私は誰ですか。 そうだ、俺はあきらめない男、三井寿だ!
  • 相关阅读:
    Apple MDM
    苹果核
    iOS自动化测试的那些干货
    Wifi 定位原理及 iOS Wifi 列表获取
    详解Shell脚本实现iOS自动化编译打包提交
    PushKit 占坑
    【译】使用 CocoaPods 模块化iOS应用
    NSMutableArray 根据key排序
    iOS 通过tag查找控件
    自己使用 2.常量变量,数据类型,数据的输入输出。
  • 原文地址:https://www.cnblogs.com/gaojunonly1/p/15450089.html
Copyright © 2011-2022 走看看