跳到正文

题解

题解 CF1267J 【Just Arrange the Icons】

gyh20约 2 分钟
原文
文章信息与版本

文章信息

收录
2026年6月14日
更新
2026年6月14日
篇幅
约 2 分钟
获赞
2
题目
CF1267J

版本

  1. v1当前

可知,答案的最大值为出现次数最少的类型的个数+1,再依次判断是否可行(具体方式见代码),时间复杂度即为出现次数最少的出现次数∗*出现过的类型数,可知,这个乘积是小于等于n的。

代码:

C++
#include<cstdio>
#include<iostream>
#define in inline
#define re register
using namespace std;
in int read() {
	re int t=0;
	re char v=getchar();	
	while(v<'0'||v>'9'){
	v=getchar();
	}	
	while(v>='0'&&v<='9'){		
	t=(t<<3)+(t<<1)+(v^48);		
	v=getchar();	}
	return t;
}
int t,n,a[2000002],mn,p[2000002],cnt;
int main(){
	t=read();
	while(t--){
		n=read();
		mn=0x7fffffff;
		cnt=0;
		bool ia=0;
		for(re int i=1;i<=n;++i)++a[read()];
		for(re int i=1;i<=n;++i)if(a[i])mn=min(mn,a[i]),p[++cnt]=a[i],a[i]=0;int ans=0;
		++mn;
		while(1){
			ans=0;
			ia=0;
			for(re int i=1;i<=cnt;++i){
				int tmp=(p[i]-1)/mn+1;
				ans+=tmp;
				if((mn-1)*tmp>p[i]){ia=1;break;
				}
			}
			if(!ia)break;
			--mn;
		}
		printf("%d\n",ans);
	}
}
原文