zoukankan      html  css  js  c++  java
  • BOJ 1580 Shoot

    Shoot

    Accept:7     Submit:7

    Time Limit:1000MS     Memory Limit:65536KB

    Description

    Kimi has two types of guns in his gun box. When Kimi use Gun 1 to shoot, there's a probability of p to hit the target. Meanwhile, when he uses Gun 2, the probability of making an accurate shoot becomes q.

    One day, Kimi went shooting with totally (a+b) guns, where a for Gun 1 and the other b for Gun 2. He randomly chose a gun in his box and began N times of shootings. But shockingly, he got all his shoots missing! However, when Kimi wanted to took the other type of gun to make the next round of shootings, he found that he didn't remember which type of gun he had taken just then. Now it becomes your task: what's the probability that he'd taken Gun 1 at the first time?

    Input Format

    An integer T(T≤100) will exist in the first line of input, indicating the number of test cases.

    Each test case consists of one line with three integers N,a,b(1≤a,b≤104,1≤N≤10) and two real numbers p,q(0≤p,q≤1).

    Output Format

    Output the probability that he'd taken Gun 1. Correct the result to 6 decimal places.

    Sample Input

    1 3 1 2 0.5 0.5

    Sample Output

    0.333333

    新生排位赛第四场的D题,一道计算概率的问题

    晚上听学长讲貌似是用了一个条件概率的公式,不过还是觉得比赛时自己那个不太专业的做法比较好理解

    具体计算的方法参见代码……

     1 #include<iostream>
     2 #include<cstdio>
     3 
     4 using namespace std;
     5 
     6 double power(double a,int b)
     7 {
     8     double result=1;
     9     for(int i=1;i<=b;i++)
    10         result*=a;
    11     return result;
    12 }
    13 
    14 int main()
    15 {
    16     int t;
    17     int n;
    18     long a,b;
    19     double p,q;
    20 
    21     scanf("%d",&t);
    22 
    23     while(t--)
    24     {
    25         double ap,bp;
    26         scanf("%d %ld %ld %lf %lf",&n,&a,&b,&p,&q);
    27         ap=a*power(1-p,n)/(a+b);
    28         bp=b*power(1-q,n)/(a+b);
    29         printf("%.6lf
    ",ap/(ap+bp));
    30     }
    31 
    32     return 0;
    33 }
    [C++]
  • 相关阅读:
    Exceptionless in Docker on Linux 搭建及部署疑难杂症
    Golang 基础语法介绍及对比(二)
    Go Windows 环境安装及配置(一)
    ElasticSearch搜索解析
    ElasticSearch文档及分布式文档存储
    ElasticSearch利用IK实现全文搜索
    ElasticSearch简要总览
    轻松驾驭统计学——数据分析必备技能
    【面试】数据分析常见问题
    【Echarts】
  • 原文地址:https://www.cnblogs.com/lzj-0218/p/3187334.html
Copyright © 2011-2022 走看看