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);
    }
  • 相关阅读:
    设置文字内容阴影效果
    android TouchEvent解析(2)
    后台运行 程序
    Intent 大全完整版
    URI URL的区别
    Java中List循环遍历的时候删除当前对象(自己)
    HDU 1005
    XML 导入 Sqlite 遇到的强大工具Navicat
    android eclipse开发环境 自动提示 程序无法响应解决方法
    DOM4J 递归解析xml文件
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4987493.html
Copyright © 2011-2022 走看看