uva 11346 Probability

來源:互聯網
上載者:User

原題:
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 ∈ [−a; a]; y ∈ [−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,b,s>=0,告訴你在座標繫上以a,b和0,0為對角線所形成矩形的面積大於s的機率。

#include <bits/stdc++.h>using namespace std;int main(){    ios::sync_with_stdio(false);    int t;    double a,b,s;    cin>>t;    while(t--)    {        cin>>a>>b>>s;        if(b>a)            swap(a,b);        if(s==0)        {            cout<<"100.000000%"<<endl;            continue;        }        if(b-s/a<=0)        {            cout<<"0.000000%"<<endl;            continue;        }        double ans=(a*b-s+s*log(s/(a*b)))/(a*b);        cout<<fixed<<setprecision(6)<<ans*100<<'%'<<endl;    }    return 0;}

解答:
上過高中的應該都會這道題。先計算出面積等於s的軌跡方程,就是y=s/x。然後求在在a和b所劃定範圍內中在軌跡方程上面的點即可。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.