首页 > 代码库 > Bzoj3093 [Fdu校赛2012] A Famous Game
Bzoj3093 [Fdu校赛2012] A Famous Game
Submit: 251 Solved: 136
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 0
4 2 1
Sample Output
Case 1: 0.5000
Case 2: 0.5000
HINT
[Explanation]
For example as the sample test one, there are three balls in the bag. The possibilities of the four possible situations are all 0.25. If there are no red balls in the bag, the possibility of the next ball are red is 0. If there is one red ball in the bag, the possibility is 1/3. If there are two red balls, the possibility is 2/3. Finally if all balls are red, the possibility is 1. So the answer is 0*(1/4)+(1/3)*(1/4)+(2/3)*(1/4)+1*(1/4)=0.5.
Source
数学问题 概率
推出来答案就是(q+1)/(p+2)
可能是近一年写过最短的代码
#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<queue>using namespace std;const int mxn=100010;int read(){ int x=0,f=1;char ch=getchar(); while(ch<‘0‘ || ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();} while(ch>=‘0‘ && ch<=‘9‘){x=x*10-‘0‘+ch;ch=getchar();} return x*f;}int n,p,q;int main(){ int cas=0; while(scanf("%d%d%d",&n,&p,&q)!=EOF){ printf("Case %d: %.4f\n",++cas,(q+1.0)/(p+2.0)); } return 0;}
Bzoj3093 [Fdu校赛2012] A Famous Game
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。