Gym100187A

来源:互联网 发布:经典java编程题 编辑:程序博客网 时间:2024/05/18 03:10

水题,不过我题目意思没看懂= =,我以为每瓶药水只能用一次,这样的话,第二组样例硬是看不懂= =

最后没做出来

题目解法:1)如果n=1,那么就不需要用兔子来测试,输出0;2)然后在n瓶药水中,把长生不老药减去,如果此时n小于k,说明无法判别出;否则:n能整除k,则结果即为n/k

否则n/k + 1

#include<cstdio>#include<iostream>#include<cstring>using namespace std;int main(){    int n,m;    while (~scanf("%d%d",&n,&m))    {        if (n == 1)            printf("0\n");        else        {            n = n - 1;            if (n < m)                printf("-1\n");            else            {                if (n % m == 0)                    printf("%d\n",n/m);                else                    printf("%d\n",n/m + 1);            }        }    }    return 0;}


0 0