P4447 [AHOI2018初中组]分组

这是个什么玩意
简单一想,就知道可以从左往右数
把相同的数字“摞”到一块
如果当前格比左边小的话,那么显然从小组到大组分就可以了
如果反之,更显然需要出现只有一个人的组
用优先队列实现这个东西就可以了.

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
std::priority_queue<int> q; 
using namespace std;
int n;
int a[1000001];
int k=1;
int chu[1000001];
int sum=0;
int now;
int cnt;
int cntt;
int tem[10000001];
int ans=999999999;
void clear(){
    while(!q.empty()){
        ans=min(ans,-q.top());
         q.pop(); 
    }
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;++i){
        scanf("%d",&a[i]);
    }
    sort(a+1,a+n+1);
    int f=0;
    for(int i=1;i<=n;++i){ 
        if(a[i]==a[i+1]){
            chu[k]++;
        }else{
            chu[k]++;
            k++;
        }
    } 
    for(int i=1;i<=k;i++){

         now+=chu[i];
         if(a[now]!=a[now-chu[i]]+1){
            clear();
         }
         cntt=1;
         if(q.size()>=chu[i]){
            for(int j=1;j<=chu[i];++j){
            tem[cntt++]=(-q.top()+1);
            q.pop();
            }
            while(!q.empty()){
                ans=min(ans,-q.top());
                 q.pop(); 
            }
            for(int j=1;j<cntt;++j){
                q.push(-tem[j]);
            }
         }else{
            while(!q.empty()){
                tem[cntt++]=(-q.top()+1);
                q.pop();
             }
            for(int j=1;j<cntt;++j){
                q.push(-tem[j]);
            }
            for(int j=cntt;j<=chu[i];++j){
                q.push(-1);
            }
         }
    }
    clear();
    cout<<ans;
    return 0;
}
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇