bludee

#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;
typedef pair<long long,int> PII;
priority_queue<PII> q;

int main()
{
    int n;
    cin>>n;
    long long ans;
    for(int i = 1;i <= n;i++)
    {
        long long high;
        scanf("%lld",&high);
        if(high!=1)          //是1就不进栈
            q.push({high,i});
    }
    
    //砍竹子
    while(!q.empty())
    {
        long long len = q.top().first;
        int num = q.top().second;
        
        long long lenc = sqrt(len/2+1);
        q.pop();
        if(lenc!=1) q.push({lenc,num});
        while(!q.empty() && q.top().first == len && q.top().second == num-1)  
//高度相等,先出编号大的
        {
            num--;
            q.pop();
            if(lenc != 1)
            {
                q.push({lenc,num});   //num为最大编号的那位编号,所以他后面的就要减1
            }
            
        }
        ans ++;
    }
    printf("%lld",ans);
    return 0;
}

pair数据 是 {}

优先数组: priority_queue 先出最大的项

定义queue的数据类型: queue<xx>

typedef  pair <xx,xx>  xx;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值