您的位置:首页 > 其它

toj 3761 Egg Problem (好题~~)

2013-11-11 20:01 197 查看

Egg Problem

时间限制(普通/Java):1000MS/3000MS 运行内存限制:65536KByte
总提交: 22 测试通过: 7


描述

There is a very interesting problem described as follows:

You are given two eggs.

You have access to a 100-storey building.

An egg that survives a fall can be used again.

A broken egg must be discarded.

The effect of a fall is the same for all eggs.

If an egg breaks when dropped, then it would break if dropped from
a higher window.

If an egg survives a fall then it would survive a shorter
fall.

It is not ruled out that the first-floor windows break eggs, nor
is it ruled out that the 100th-floor windows do not cause an egg to break.

You need to figure out the highest floor an egg can be dropped
without breaking. The question is how many drops you need to make.

Now, I want to know how to solve this problem for any number of eggs and any
storeys. Can you help me?

输入

In the first line there is an integer T (T <= 10000), indicates the number
of test cases.

In each case, there are two integers n and m (1 <= n <= 15, 1 <= m
<= 100000), which are the number of eggs and storeys.

输出

For each case, the output format is “Case c: ans”.

c is the case number start from 1.

ans is the answer of this problem.

样例输入

2
2 100
3 100


样例输出

Case 1: 14
Case 2: 9


题目来源

2011年绍兴市赛

原理:http://blog.sina.com.cn/s/blog_6c813dbd0101bh98.html

推导过程:/article/2801243.html

#include <stdio.h>
int dp[20][100010];
void Init(){
for(int i=1; i<=15; i++){
for(int j=1; j<=100000; j++){
if(i == 1) dp[i][j] = j;
else if(i == j) dp[i][j] = (1<<i)-1;
else if(i >= j) dp[i][j] = dp[j][j];
else if(i < j)  dp[i][j] = dp[i-1][j-1] + 1 + dp[i][j-1];
if(dp[i][j]>=100000){
break;
}
}
}
}
int main()
{
int T;
Init();
scanf("%d", &T);
for(int cas=1; cas<=T; cas++){
int n, m;
scanf("%d %d", &n, &m);
for(int i=1; ; i++){
if(dp
[i] >= m){
printf("Case %d: %d\n", cas, i);
break;
}
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: