Welcome

首页 / 软件开发 / 数据结构与算法 / HDU 4254 A Famous Game (概率&组合数学公式)

HDU 4254 A Famous Game (概率&组合数学公式)2014-07-10 synapse7 A Famous Game

http://acm.hdu.edu.cn/showproblem.php?pid=4254

Time Limit: 2000/1000 MS (Java/Others)

Memory Limit: 32768/32768 K (Java/Others)

Problem Description

Mr. B and Mr. M like to play with balls. They have many balls colored in blue and red. Firstly, Mr. B randomly picks up N balls out of them and put them into a bag. Mr. M knows that there are N+1 possible situations in which the number of red balls is ranged from 0 to N, and we assume the possibilities of the N+1 situations are the same. But Mr. M does not know which situation occurs. Secondly, Mr. M picks up P balls out of the bag and examines them. There are Q red balls and P-Q blue balls. The question is: if he picks up one more ball out of the bag, what is the possibility that this ball is red?

Input

Each test case contains only one line with three integers N, P and Q (2 <= N <= 100,000, 0 <= P <= N-1, 0 <= Q <= P).

Output

For each test case, display a single line containing the case number and the possibility of the next ball Mr. M picks out is red. The number should be rounded to four decimal places.

Sample Input

3 0 04 2 1
Sample Output

Case 1: 0.5000Case 2: 0.5000

Source

Fudan Local Programming Contest 2012

解析见这,但我觉得里面有个公式有点问题。。

完整代码:

/*0ms,260KB*/#include <cstdio>int main(void){int T = 0, n, p, q;while (~scanf("%d%d%d", &n, &p, &q))printf("Case %d: %.4f
", ++T, (q + 1.0) / (p + 2));return 0;}