fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. float w=0;
  4. double ans(float n,float m)
  5. {
  6. if(m>=2)
  7. {
  8. return n/(n+m)+(m/(n+m))*(m-1/(n+m-1))*ans(n,m-2);
  9. }
  10. else
  11. {
  12. return n/(n+m);
  13. }
  14. }
  15. int main()
  16. {
  17. int t;
  18. cin>>t;
  19. while(t>0)
  20. {
  21. int n,m;
  22. cin>>n>>m;
  23. float a,b;
  24. a=n;
  25. b=m;
  26. float k;
  27. // float k=a/(a+b);
  28. /*int e=k;
  29.   if(e==1)
  30.   k=1.000000;
  31.   */
  32. if(n==0||m==0)
  33. k=1.0;
  34. else
  35. k= ans(a,b);
  36. cout<<fixed<<setprecision(6)<<k<<endl;
  37.  
  38.  
  39.  
  40. t--;
  41. }
  42. }
Success #stdin #stdout 0s 4516KB
stdin
10
1 0
0 0
0 1
1000 0
0 1000
999 999
882 456
345 234
12 45
345 56
stdout
1.000000
1.000000
1.000000
1.000000
1.000000
inf
inf
inf
569572334543773729030144.000000
85213749248.000000