zoukankan      html  css  js  c++  java
  • Codeforces Round #185 (Div. 2) B. Archer 水题

    B. Archer

    Time Limit: 20 Sec

    Memory Limit: 256 MB

    题目连接

    http://codeforces.com/contest/312/problem/B

    Description

    SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is  for SmallR while  for Zanoes. The one who shoots in the target first should be the winner.

    Output the probability that SmallR will win the match.

    Input

    A single line contains four integers .

    Output

    Print a single real number, the probability that SmallR will win the match.

    The answer will be considered correct if the absolute or relative error doesn't exceed 10 - 6.

    Sample Input

    1 2 1 2

    Sample Output

    0.666666666667

    HINT

    题意

    第一个人有a/b的概率射中靶子,第二个人有c/d的概率射中靶子,两个人轮流射

    然后问你有多大的概率第二个人最先射中靶子

    题解:

    水题啦,很容易推公式,发现是一个等比数列,然后求和就好了

    也可以不求和,直接暴力for也行

    代码:

    #include<iostream>
    #include<stdio.h>
    #include<math.h>
    using namespace std;
    
    
    int main()
    {
        double a,b,c,d;
        cin>>a>>b>>c>>d;
        double p1 = a/b,p2 = c/d;
        double ans = 0;
        double p = 1;
        for(int i=0;i<10000;i++)
        {
            ans += p*(1-p1)*p2;
            p = p * (1-p1) * (1-p2);
        }
        printf("%.10f
    ",1-ans);
    }
  • 相关阅读:
    C++学习网址
    python学习网址
    python之raw_input()函数
    APP营销模式
    计划任务
    多线程
    Spring Aware
    事件(Application Event)
    Spring 的AOP
    Java配置
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4987493.html
Copyright © 2011-2022 走看看