【Codeforces Gym 100187A】
2017-03-20 20:22
260 查看
A - A Gym - 100187A
The world famous scientist Innokentiy has just synthesized the potion of immortality. Unfortunately, he put the flask with this potion on the shelf where most dangerous poisons of all time were kept. Now there are n flasks on this shelf, and the scientist has no idea which of them contains the potion of immortality.
Fortunately, Innokentiy has an infinite amount of rabbits. But the scientist doesn’t know how exactly these potions affect rabbits. There is the only thing he knows for sure. If rabbit tastes exactly k potions from the flasks on the shelf, it will survive if there was the immortality potion among them and die otherwise. If rabbit tastes the number of potions different from k, the result will be absolutely unpredictable, so the scientist won’t make such experiments no matter what.
The scientist intends to minimize the amount of lost rabbits while searching for the potion of immortality. You should determine how many rabbits he has to sacrifice in the worst case.
Input
The only line contains two integers separated by space — n and k (1 ≤ n ≤ 2000, 1 ≤ k ≤ n) — the number of flasks on the Innokentiy’s shelf and the number of potions Innokentiy will give to a single rabbit to taste.
Output
If the scientist cannot determine which flusk contains the potion of immortality, output «-1». Otherwise, output a single integer — the minimal number of rabbits that Innokentiy will sacrifice in the worst case while searching for the potion of immortality.
Example
Input
3 2
Output
1
Input
4 2
Output
2
喝解药的兔子一直不会死~~
AC代码:
The world famous scientist Innokentiy has just synthesized the potion of immortality. Unfortunately, he put the flask with this potion on the shelf where most dangerous poisons of all time were kept. Now there are n flasks on this shelf, and the scientist has no idea which of them contains the potion of immortality.
Fortunately, Innokentiy has an infinite amount of rabbits. But the scientist doesn’t know how exactly these potions affect rabbits. There is the only thing he knows for sure. If rabbit tastes exactly k potions from the flasks on the shelf, it will survive if there was the immortality potion among them and die otherwise. If rabbit tastes the number of potions different from k, the result will be absolutely unpredictable, so the scientist won’t make such experiments no matter what.
The scientist intends to minimize the amount of lost rabbits while searching for the potion of immortality. You should determine how many rabbits he has to sacrifice in the worst case.
Input
The only line contains two integers separated by space — n and k (1 ≤ n ≤ 2000, 1 ≤ k ≤ n) — the number of flasks on the Innokentiy’s shelf and the number of potions Innokentiy will give to a single rabbit to taste.
Output
If the scientist cannot determine which flusk contains the potion of immortality, output «-1». Otherwise, output a single integer — the minimal number of rabbits that Innokentiy will sacrifice in the worst case while searching for the potion of immortality.
Example
Input
3 2
Output
1
Input
4 2
Output
2
喝解药的兔子一直不会死~~
AC代码:
#include<cstdio> int main() { int N,K; scanf("%d %d",&N,&K); if(N == 1) printf("0\n"); else if(N == K) printf("-1\n"); 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); } return 0; }
相关文章推荐
- Codeforces Gym 100418A A - A+-B java高精度
- Codeforces Gym 100286A. Aerodynamics 计算几何 求二维凸包面积
- Codeforces Gym 100379G Wythoff’s game with three piles 博弈
- Codeforces Gym 100203G G - Good elements 暴力
- Codeforces gym 2013-2014 Samara SAU ACM ICPC Quarterfinal Qualification Contest
- codeforces Gym 100431G Persistent Queue
- CodeForces Gym 101620简要题解
- Codeforces Gym - 101635G [KM]
- Codeforces Gym 100002 B Bricks 枚举角度
- CodeForcesGym 100735D Triangle Formation
- Codeforces Gym 100803C Shopping 贪心好题
- codeforces Gym 100971 A、B、C、F、G、K、L
- Codeforces GYM 100962J: Jimi Hendrix 题解
- Codeforces Gym 100623C Problem C. Class
- CodeForcesGym 100517H Hentium Scheduling
- [DP 决策单调性] Codeforces Gym 101002H .Jewel Thief
- Codeforces gym 101350A dp
- Codeforces gym 101149 L 最短路
- Codeforces Gym 100589A Queries on the Tree(树状数组+分块)
- CodeForces Gym 101741 简要题解