cf 77b Falling Anvils 概率水题

 

给出a,b

p的范围为[0,a],q的范围为[-b,b]

0<=a<10,0<=b<10

现在给出a,b

 有实数根的概率

有实数根,则p-4*q>=0,即p>=4*q

画个坐标轴,就知道了,几何概型

注意:0不能作为分母

 1 #include<iostream>
 2 
 3 using namespace std;
 4 int main()
 5 {
 6     int test;
 7     cin>>test;
 8     while(test--)
 9     {
10         double a,b;
11         cin>>a>>b;
12         if(a==0&&b==0)
13         {
14             cout<<1<<endl;
15         }
16         else if(a==0&&b>0)
17         {
18             cout<<0.5<<endl;
19         }
20         else if(a>=4.0*b)
21         {
22            cout<<(a-b)/a<<endl;
23         }
24         else
25         {
26             cout<<(a/4.0+2*b)/(4*b)<<endl;
27         }
28     }
29     return 0;
30 }
View Code
原文地址:https://www.cnblogs.com/-maybe/p/4684809.html