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, with balls. They have many balls colored in blue and red. Firstly, Mr. B randomly picks up N balls out of the them and put them into a bag. Mr. M knows that there are n+1 possible situations in which the number of red balls be ranged from 0 to N, and we assume t He 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, and what is the possibility so 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 is rounded to four decimal places.
Sample Input
3 0 04 2 1
Sample Output
Case 1:0.5000case 2:0.5000
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/
Source
Fudan Local Programming Contest 2012
I see this, but I think there's a problem with the formula.
Complete code:
/*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\n", ++t, (q + 1.0)/(P + 2));
return 0;
}