题意:
给你一个公式 ,
给你一个的范围在,的范围在
问你一对可以使上面的式子成立概率。
思路:
因为有解,所以
假设
那么满足:
所以只需要求出y=4x以下的面积就行。
第一种:
第二种:
代码:
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e6+10;
pair<int,int> f[N];
int x[N],y[N];
void solve(){double p,q;cin>>p>>q;q=q*4.0;if(q==0){cout<<"1.00000000\n";return ;}if(p==0){if(q==0){cout<<"1.0000000\n";return ;}else {cout<<"0.5000000\n";return ;}}double sum=0.0;if(p>=q){sum=((p*2.0*q)-q*q*0.5)*1.0/(p*2.0*q);}else {sum=((p*2.0*q)-p*p*0.5-(q-p)*1.0*p)/(p*2.0*q);}cout<<fixed<<setprecision(8)<<sum<<"\n";
}
signed main(){ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); int t=1;cin>>t;while(t--){solve();}
}