24h購物| | PChome| 登入
2013-08-11 20:42:35| 人氣2,044| 回應0 | 上一篇 | 下一篇

[UVA][積分] 11346 - Probability

推薦 0 收藏 0 轉貼0 訂閱站台

G - 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%

Problem setters: Aleksej Viktorchik, Leonid Shishlo.
Huge Easy Contest #1


題目描述:

取樣點 P (x, y), -a <= x <= a, -b <= y <= b

問 P 與 (0, 0) 矩形面積大於等於 S 的機率為何?

這個矩形邊長平行 x 軸和 y 軸。

題目解法:

積分,先考慮第一象限可行的 P 面積,得到結果如下:



gif.latex.gif


[UVA][積分] 11346 - Probability

最後將面積 *4 / 總面積 = 機率。


#include <stdio.h>
#include <math.h>
int main() {
    double a, b, S;
    int testcase;
    scanf("%d", &testcase);
    while(testcase--) {
        scanf("%lf %lf %lf", &a, &b, &S);
        double ret = 0;
        if(S/a >= b) {}
        else if(S/b >= a) {}
        else
            ret = b*(a-S/b)-S*log(a)+S*log(S/b+1e-8);
        printf("%.6lf%%\n", ret*100.0/(a*b));
    }
    return 0;
}

台長: Morris
人氣(2,044) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 教育學習(進修、留學、學術研究、教育概況) | 個人分類: UVA |
此分類下一篇:[UVA] 12457 - Tennis contest
此分類上一篇:[UVA][dp] 11176 - Winning Streak

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文