fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. double GetProb(double r,double g,double t)
  5. {
  6. double ans;
  7.  
  8. if(g>=2)
  9. {ans= (g/t)*((g-1)/(t-1))*GetProb(r,g-2,t-2);
  10. return ans;
  11. }
  12. else
  13. {
  14. ans=r/t;
  15. return t;
  16. }
  17. }
  18.  
  19. int main()
  20. {
  21. int t;
  22. cin>>t;
  23. while(t-->0)
  24. {
  25. double r,g,t;
  26. cin>>r>>g;
  27. t = r+g;
  28. if(r==0)
  29. cout<<"1.000000"<<endl;
  30. else
  31. {
  32. double ans = GetProb(r,g,t);
  33. printf("%0.6lf\n",ans);
  34. }
  35. }
  36. }
Success #stdin #stdout 0s 4248KB
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
1000.000000
1.000000
0.000000
0.000000
0.000000
0.000000
0.000000