题意理解了就很好做了。当时理解错了。。。
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
int main()
{
int n, k;
scanf("%d%d",&n,&k);
if(n==1)
{
cout<<0<<endl;
return 0;
}
if(n == k)
{
cout<<-1<<endl;
return 0;
}
if(k == 1)
cout<<n-1<<endl;
else
{
int r = n%k;
if(r == 0|| r ==1)
cout<<n/k<<endl;
else
cout<<n/k+1<<endl; // 不管余数是多少,最糟的情况是前面的全部死了,然后剩下n%k瓶未知的,
<span style="white-space:pre"> </span>//每次把前面的k-1瓶毒药和一瓶未知的,如果死,则找到了,不死,继续 直到最后剩下两瓶,死多一只。。。所以 只需要n/k+1
}
return 0;
}