您的位置:首页 > 其它

uva 11346 Probability

2016-03-08 19:29 344 查看
原题:

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所划定范围内中在轨迹方程上面的点即可。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: