Gym - 100187A A - Potion of Immortality —— 贪心

题目链接:http://codeforces.com/gym/100187/problem/A


题解:

光题意就想了很久:在最坏情况下的最小兔子数。其实就是至少用几只兔子就一定能找出仙药(答案存在的话)。再注意一下特殊情况就可以了,


代码如下:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <sstream>
#include <algorithm>
using namespace std;
#define pb push_back
#define mp make_pair
#define ms(a, b)  memset((a), (b), sizeof(a))
//#define LOCAL
#define eps 0.0000001
typedef long long LL;
const int inf = 0x3f3f3f3f;
const int maxn = 200000+10;
const int mod = 1000000007;

int main()
{
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
//      freopen("output.txt", "w", stdout);
    #endif // LOCAL
    int n,k;
    cin>>n>>k;
    if(n==1) puts("0");
    else if(n==k) puts("-1");
    else if(k==1) printf("%d\n",n-1);
    else
    {
        if(n%k==0||n%k==1)
            printf("%d\n",n/k);
        else
            printf("%d\n",n/k+1);
    }
}


转载于:https://www.cnblogs.com/DOLFAMINGO/p/7538729.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值