论昨天CF的B题
  • 板块灌水区
  • 楼主星空舞涵
  • 当前回复2
  • 已保存回复2
  • 发布时间2020/10/1 07:49
  • 上次更新2023/11/5 12:20:58
查看原帖
论昨天CF的B题
243750
星空舞涵楼主2020/10/1 07:49

我的代码,随便瞎搞出来的,但是最后因为没加特判死了。

有没有大佬证明一下正确性呀

#include<bits/stdc++.h>
using namespace std;
long long tt,k,m,a[101],b[101],ans,t[101],zhong,n;
int main()
{
	cin>>tt;
	while(tt--)
	{
		memset(t,0,sizeof(t));
		cin>>n>>k;
		ans=0;
		zhong=0;
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
			if(t[a[i]]==0)
			{
				t[a[i]]=1;	
				zhong++;
			}
			else t[a[i]]++;
		}
		
		if(k==1)
		{
			if(zhong==1)cout<<1<<endl;
			else cout<<"-1"<<endl;
		}
		else if(zhong==1)
		{
			cout<<1<<endl;
		}
		else 
		{	zhong--;
			ans=zhong/(k-1);
			if(zhong%(k-1)!=0)ans++;
			cout<<ans<<endl;	
		}
	}
}
2020/10/1 07:49
加载中...