标签:统计 bit turn pop int using 队列 efi def
排序后扫一遍,维护当前分组方案,尽量加入人数少的组。如果某些组再也不可能加入了就统计最小值,如果每组都加入过了相同的实力值就新开一组。
因为组的信息具有单调性,所以可以用双端队列 \(O(n)\) 维护。
code:
#include<bits/stdc++.h>
using namespace std;
#define Min(x,y)((x)<(y)?x:y)
#define For(i,x,y)for(i=x;i<=(y);i++)
int a[100005];
deque<pair<int,int> >deq;
int main()
{
int n,i,mn;
scanf("%d",&n);
mn=n;
For(i,1,n)scanf("%d",&a[i]);
sort(a+1,a+n+1);
For(i,1,n)
{
if(deq.empty())
{
deq.push_back(make_pair(a[i],1));
continue;
}
while(!deq.empty())
if(deq.front().first+1<a[i])mn=Min(mn,deq.front().second),deq.pop_front();
else break;
if(deq.empty()||deq.front().first==a[i])
{
deq.push_front(make_pair(a[i],1));
continue;
}
deq.push_back(make_pair(deq.front().first+1,deq.front().second+1));
deq.pop_front();
}
while(!deq.empty())mn=Min(mn,deq.front().second),deq.pop_front();
printf("%d",mn);
return 0;
}
标签:统计 bit turn pop int using 队列 efi def
原文地址:https://www.cnblogs.com/May-2nd/p/14906185.html