0
点赞
收藏
分享

微信扫一扫

ZCMU—1894

慕容冲_a4b8 2022-09-07 阅读 216



1894: Power Eggs


Time Limit: 1 Sec   Memory Limit: 128 MB

Submit: 45  

Solved: 18

[​Submit​​][​Status​​][​Web Board​​]


Description


Benedict bought K identical power eggs from Dropeggs.com, and now he wants to test them by dropping them from different floors of his building. His building has N floors numbered 1 to NF is an unknown number in the range from 0 to N, inclusive. Each egg will break if dropped from floor F+1 or above, but will not break if dropped from floor F or below. Benedict can drop each egg as many times as he wants from any floor until it breaks. He wants to know the minimum number of egg drops necessary to ensure that he can determine F.

For example, if there are three floors and Benedict has only one egg, then he has to first throw the egg from the first floor, then from the second floor (if the egg survived), and then from the third floor (if the egg survived). Therefore, three drops are required in the worst case.


Input


The first line contains one number  T  (1 ≤  T  ≤ 10000) which is the number of test cases, followed by  T  lines. Each of the next  T  lines contains two numbers:  N , the number of floors (1 ≤  N  ≤ 2000000007) and  K , the number of eggs (1 ≤  K  ≤ 32).


Output


For each of the  T  lines, print the minimal number of drops required, or if it's greater than 32, print the word Impossible . After that many drops, Benedict gets too tired and cannot continue.


Sample Input


4

10 1

100 2

30 30

2000000000 2


Sample Output


10

14

5


Impossible


【分析】


刘汝佳老师写过经典的鹰蛋dp.....占了做过的优势,所以出的特别快...


首先要注意下边界...不要被数据范围吓到了...只要32步算不出答案,那就是Impossible...


f[i][j]表示剩余i次测试j个鸡蛋能测出来的最大层数


那么对于当前f[i][j]的状态


我们可以考虑,如果从某个位置扔鸡蛋,如果碎了,状态就是f[i-1][j-1]


如果没碎状态就是f[i-1][j],所以 状态转移很明显就是f[i][j]=f[i-1][j-1]+f[i-1][j]


那么考虑一下初始化...


如果只剩一次测试机会,那么f[1][j]就是2,鸡蛋再多也没用。


另外一个情况就是如果这个鸡蛋非常强力...怎么都不碎,那么就是f[i][1],可以达到的位置就是n+1


为什么+1是因为楼层区间是[0,n],总共n+1


【代码】


#include <stdio.h>
long long f[33][33];
int main()
{
for (int i=1;i<33;i++) f[i][1]=i+1,f[1][i]=2;
for (int i=2;i<33;i++)
for (int j=2;j<33;j++)
f[i][j]=f[i-1][j-1]+f[i-1][j];
int pp;scanf("%d",&pp);
while (pp--)
{
long long n,m;scanf("%lld%lld",&n,&m);
for (int i=1;i<33;i++)
if (f[i][m]-1>=n)
{
printf("%d\n",i);
goto out;
}
printf("Impossible\n");
out:;
}
}




举报

相关推荐

力扣1894

ZCMU—A

ZCMU—1263

ZCMU—1374

ZCMU—1306

ZCMU—1798

ZCMU—1776

ZCMU—1676

0 条评论