再开一贴!!

emailed 2008-04-22 05:50:21
In the game show "The Price is Right", a number of players (typically 4) compete to get on stage by guessing the price of an item. The winner is the person whose guess is the closest one not exceeding the actual price. Because of the popularity of the one-person game show "Who Wants to be a Millionaire", the American Contest Management (ACM) would like to introduce a one-person version of the "The Price is Right". In this version, each contestant is allowed G (1 ≤ G ≤ 30) guesses and L (0 ≤ L ≤ 30) lifelines. The contestant makes a number of guesses for the actual price. After each guess, the contestant is told whether it is correct, too low, or too high. If the guess is correct, the contestant wins. Otherwise, he uses up a guess. Additionally, if his guess is too high, a lifeline is also lost. The contestant loses when all his guesses are used up or if his guess is too high and he has no lifelines left. All prices are positive integers.

It turns out that for a particular pair of values for G and L, it is possible to obtain a guessing strategy such that if the price is between 1 and N (inclusive) for some N, then the player can guarantee a win. The ACM does not want every contestant to win, so it must ensure that the actual price exceeds N. At the same time, it does not want the game to be too diffcult or there will not be enough winners to attract audience. Thus, it wishes to adjust the values of G and L depending on the actual price. To help them decide the correct values of G and L, the ACM has asked you to solve the following problem. Given G and L, what is the largest value of N such that there is a strategy to win as long as the price is between 1 and N (inclusive)?


Input

The input consists of a number of cases. Each case is specified by one line containing two integers G and L, separated by one space. The end of input is specified by a line in which G = L = 0.


Output

For each case, print a line of the form:

Case c: N

where c is the case number (starting from 1) and N is the number computed.


Sample Input

3 0
3 1
10 5
7 7
0 0


Sample Output

Case 1: 3
Case 2: 6
Case 3: 847
Case 4: 127

...全文
78 点赞 收藏 6
写回复
6 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
emailed 2008-04-23
好,谢谢了,结贴了,再看下一个
回复
保证1~N范围里的任何一个数都能在G,L的情况下通过某种策略猜出来。如果N再大一点,其中有些数就可能猜不中了。这是“连续”所指的意思。

你把样例输出中的N调大一些,都能找到猜不出的反例。
回复
emailed 2008-04-23
嗯,你这样说是正确的,但是好像你说的这个“连续”的意思好像没太看出来啊。。
回复
共有G次猜价格的机会,机会用完还没猜中就意味着失败。特殊的是,这里有一个L条“命”的特殊限制,价格猜高了要被罚掉一条“命”,当“命”的数量变成负数的时候竞赛者也得出局,所以“命”的数量也影响到竞猜的策略。这个题目要求给出G、L之后,算出这种条件下所能猜到的最大连续整数(1~N)的范围。

拿样列中的例子来说:
3 0:由于L=0,这意味着不能有任何一次猜测高于实际价格,所以只能采取最“安全”的策略,1、2、3这样猜下去,最多也只能连续到3;

3 1:和上面不同,这里竞赛者有一次往高里猜价的机会,所以可以变得“大胆”一些。
第一次猜3
如果猜高了,那么剩下两次机会依次猜1和2(这个分支的其实是N(2,0),被罚掉了一条命);
如果猜低了(注意依然有L=1),下一次可以猜5,然后根据反馈的结果,最后一次可以猜4或者6(这个分支对应的其实是N(2,1)).
因此所能达到的最大连续整数只能到6。

从上面的例子其实可以看出,当我们猜了1次价格之后:
如果第一次猜高了,那么更低的价格通过N(G-1,L-1)可以猜出来;
如果第一次猜低了,那么更高的价格只能通过N(G-1,L)来猜测。
所以有N(G,L)=N(G-1,L-1)+1+N(G-1,L),这就是所能覆盖到的最大连续整数范围。
回复
emailed 2008-04-22
这题是什么意思都搞不懂啊。。。。
回复
边界条件:N(G,0)=G,N(0,L)=0
递推公式:N(G,L)=N(G-1,L-1)+1+N(G-1,L)
回复
相关推荐
发帖
数据结构与算法
创建于2007-08-27

3.2w+

社区成员

数据结构与算法相关内容讨论专区
申请成为版主
帖子事件
创建了帖子
2008-04-22 05:50
社区公告
暂无公告