• UVA


    Description

     Probability

    Time Limit: 1 sec  Memory Limit: 16MB

    Consider rectangular coordinate system and point L(X,Y) which is randomly chosen among all points in the area A which is defined in the following manner: A = {(x,y) | x is from interval [-a;a]; y is from interval [-b;b]}. What is the probability P that the area of a rectangle that is defined by points (0,0) and (X,Y) will be greater than S?

    INPUT:

    The number of tests N <= 200 is given on the first line of input. Then N lines with one test case on each line follow. The test consists of 3 real numbers a > 0, b > 0 ir S => 0.

    OUTPUT:

    For each test case you should output one number P and percentage " %" symbol following that number on a single line. P must be rounded to 6 digits after decimal point.

    SAMPLE INPUT:

    3
    10 5 20
    1 1 1
    2 2 0
    

    SAMPLE OUTPUT:

     23.348371%
    0.000000%
    100.000000%
    题意:给定a,b,s要求在[-a,a]选定x,在[-b,b]选定y,使得(0, 0)和(a,b)组成的矩形面积大于s的概率
    思路:只需要求第一象限的即可,转换成a*b>s的图形面积,利用求导函数求面积的方式计算,总面积为m=a*b,求所以概率为(m-s-s*log(m/s))/m.
    #include <iostream>
    #include <cstdio>
    #include <cmath>
    using namespace std;
    int main (){
        int num;
        scanf("%d",&num);
        while(num--){
            double a,b,s;
            scanf("%lf%lf%lf",&a,&b,&s);
            if(s > a*b)
                printf("0.000000%%
    ");
            else if(s ==0)
                printf("100.000000%%
    ");
            else{
                double m = a * b;
                double ans = (m - s - s * log(m/s)) / m;
                printf("%.6lf%%
    ",ans*100);
            }
        }
        return 0;
    }
  • 相关阅读:
    将oh-my-zsh编程真正的my zsh
    Linux Shell 程序调试
    (64位)本体学习程序(ontoEnrich)系统配置说明文档
    Shell编程——vim常用命令
    Morris Traversal 方法遍历二叉树(非递归、不用栈,O(1)空间)
    206. Reverse Linked List
    欧几里德算法求解最大公约数
    25. Reverse Nodes in k-Group
    86. Partition List
    24. Swap Nodes in Pairs
  • 原文地址:https://www.cnblogs.com/hfc-xx/p/4741253.html
Copyright © 2020-2023  润新知