原題:
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所劃定範圍內中在軌跡方程上面的點即可。