zoukankan      html  css  js  c++  java
  • BZOJ 3093: [Fdu校赛2012] A Famous Game

    3093: [Fdu校赛2012] A Famous Game

    Time Limit: 1 Sec  Memory Limit: 128 MB
    Submit: 248  Solved: 133
    [Submit][Status][Discuss]

    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

    分析:

    代码:

    #include<algorithm>
    #include<iostream>
    #include<cstring>
    #include<cstdio>
    //by NeighThorn
    using namespace std;
    
    int n,p,q,cas;
    
    signed main(void){
    	cas=0;
    	while(scanf("%d%d%d",&n,&p,&q)!=EOF)
    		printf("Case %d: %.4f
    ",++cas,1.0*(q+1)/(1.0*(p+2)));
    	return 0;
    }
    

      


    By NeighThorn

  • 相关阅读:
    各种语言语法大全
    【mysql】SQL常用指令
    【JdbcTemplete】JdbcTemplete代码详解--模板方法详解
    【Spring-AOP-1】AOP相关概念
    【设计模式】命令行模式
    【设计模式】单件模式(Singleton)--各类单件模式的比较
    【设计模式】工厂方法模式(Factory Method)
    【设计模式】装饰者模式(Decorator)
    【并发编程】延时初始化
    【并发编程】AQS学习
  • 原文地址:https://www.cnblogs.com/neighthorn/p/6440645.html
Copyright © 2011-2022 走看看