Pocky HDU 5984 (geometric probability model - desired)

The original title

link

Resolve

Provided the function f (x) represents the length of the rod to a desired value cutoff frequency x.

(1) significantly when x <= d, f (x) = 0;

(2) 当f(x)>d时,f(x)=1+f(0~d)+f(d~x).

1 must be cut represents a, f (0 ~ d) represents a cut of the desired value remaining after the length 0 ~ d, f (d ~ x) indicates the remainder after the first cut at a desired value d ~ x length.

From (1) known, f (0 ~ d) = 0, the key is to find f (d ~ x), a cut length of the rod of x, the probability of both truncated 1 / x, thus f (d ~ x) = (1 / x) * ∫ (x, d) f (x) dx.

There are f (x) = 1 + ( 1 / x) * ∫ (x, d) f (x) dx, derivation sides, F '(X) = - (. 1 / X 2 ) * ∫ (X, D) f (x) dx + (1 / x) f (x). simultaneous f (x) and f '(x) of the expression evaluates is, f' (x) = 1 / x, then f (x) = lnx + C, the f (d) = 1 is substituted into solve for C = -lnd + 1.

To sum up there

f(x)={0,x<=d

   {lnx-lnd+1,x>d

Code

 1 #include <iostream>
 2 #include <cmath>
 3 
 4 using namespace std;
 5 
 6 typedef long long LL;
 7 
 8 int main()
 9 {
10     int t;
11     cin>>t;
12     while(t--)
13     {
14         double x,y;
15         scanf("%lf %lf",&x,&y);
16         if(x<=y) printf("0.000000\n");
17         else printf("%.6f\n",log(x)-log(y)+1);
18     }
19     return 0;
20 }

 

Guess you like

Origin www.cnblogs.com/VBEL/p/11956932.html