CodeForces Gym 100187 A Potion of Immortality
2017-03-20 21:19
197 查看
http://codeforces.com/gym/100187/problem/A
A. Potion of Immortality
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
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.
Examples
input
output
input
output
题意理解错了。。。以为只有一种毒药。
有n种药,只有一瓶不是毒药,一只兔子每次和k种,问最坏的情况下最少毒死几只兔子。。。
思路:注意n=0,n=k,k=1的情况。
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
int i,j,k,n;
while(scanf("%d%d",&n,&k)!=EOF)
{
if(n==1)
{
printf("0\n");
continue;
}
if(n==k)
{
printf("-1\n");
continue;
}
if(k==1)
{
printf("%d\n",n-1);
continue;
}
if(n%k==0||n%k==1)
{
printf("%d\n",n/k);
}
else printf("%d\n",n/k+1);
}
return 0;
}
A. Potion of Immortality
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
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.
Examples
input
3 2
output
1
input
4 2
output
2
题意理解错了。。。以为只有一种毒药。
有n种药,只有一瓶不是毒药,一只兔子每次和k种,问最坏的情况下最少毒死几只兔子。。。
思路:注意n=0,n=k,k=1的情况。
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
int i,j,k,n;
while(scanf("%d%d",&n,&k)!=EOF)
{
if(n==1)
{
printf("0\n");
continue;
}
if(n==k)
{
printf("-1\n");
continue;
}
if(k==1)
{
printf("%d\n",n-1);
continue;
}
if(n%k==0||n%k==1)
{
printf("%d\n",n/k);
}
else printf("%d\n",n/k+1);
}
return 0;
}
相关文章推荐
- codeforces Gym 100187A A. Potion of Immortality
- codeforces Gym 100187D Holidays(排列组合)
- codeforces gym 2016-2017 NEERC, Moscow Subregional K. Knights of the Old Republic 最小生成树+dp
- codeforces Gym 100500C D.Hall of Fame 排序
- Codeforces Gym 101158 B. Quality of Check Digits (模拟)
- Codeforces gym 100685 E. Epic Fail of a Genie 贪心
- Codeforces Gym 101158 F. Three Kingdoms of Bourdelot
- Codeforces Gym 100187D D. Holidays 排列组合
- codeforces Gym 100500H A. Potion of Immortality 简单DP
- Gym 100187A - Potion of Immortality
- [杂题] Codeforces Gym 101190 NEERC 16 L. List of Primes
- codeforces Gym 100187H H. Mysterious Photos 水题
- [分治 杂题] Codeforces Gym 101173 CERC 16 G & BZOJ 4792 Geohash Grid
- Codeforces Round #115 B. Plane of Tanks: Pro 水题
- 【DFS】Gym - 101142C - CodeCoder vs TopForces
- Codeforces Gym 101234H Split Game
- UVA Live 7958 (Codeforces Gym 101201G) Maximum Islands 二分图染色+匹配
- Codeforces Gym 100002 B Bricks 枚举角度
- Codeforces Gym 100339I Sum vs Product 剪枝搜索
- [二分答案 2-SAT验证 前缀后缀优化建图 线段树优化建图] Codeforces gym 100159 Facebook Hacker Cup 2012 I. Unfriending