[958(div.2)A. Split the Multiset](Problem - A - Codeforces)
每次把数拆分成K-1个1和第K个数(设为x),然后再去判断x是拆分几次。弄了个循环。
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
int cnt=0;
int n,k;
void slove(int x)
{
while(x>k) //每次把该数拆分成k-1个1和第K个数x。
{
x-=k-1;
cnt++; //拆分次数累加。
}
cnt++; //循环出来时一定是x<=k;该数拆分1次就行,所以cnt累加1次。
}
int main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t;
cin>>t;
while(t--)
{
cnt=0; //统计拆分次数
cin>>n>>k;
if(n==1)
{
cout<<0<<endl; //如果n为1则不用拆分
continue;
}else if(n>1&&n<=k)
{
cout<<1<<endl; //如果n<=k,则拆分1次就都是1的组合了。
continue;
}else{
slove(n); //只有当n>k时才需要判断几次。
}
cout<<cnt<<endl;
}
return 0;
}