我的代码,随便瞎搞出来的,但是最后因为没加特判死了。
有没有大佬证明一下正确性呀
#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;
}
}
}