0分蒟蒻求救
查看原帖
0分蒟蒻求救
1276934
liuziqiputuo楼主2024/11/2 19:30

自己测正确提交就RE

#include<bits/stdc++.h>
using namespace std;
int a[100005],n,ans=1e9,b[100005],c,t[100005];
int main()
{
	cin>>n;
	for(int i=1;i<=n;++i)cin>>a[i];
	sort(a+1,a+1+n);
	t[0]=1e9;
	for(int i=1;i<=n;++i)
	{
		int l=0,r=c,mid; 
		while(l<r)
		{
	 	    mid=ceil((l+r)/2.0);
			if(a[i]>=t[mid])l=mid;
			else r=mid-1;
		}
		if(t[mid]!=a[i])
		{
			c++; 
			b[c]=1;
			t[c]=a[i]+1;
		}
		else 
		{
			b[mid]++;
			t[mid]++;
		}
	}
	for(int i=1;i<=c;++i)if(b[i]<ans)ans=b[i];
	cout<<ans<<endl;
	return 0;
}

2024/11/2 19:30
加载中...