fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. #define ins insert
  5. #define pb push_back
  6. #define vi vector <int>
  7. #define vl vector<long long int>
  8. #define pi pair<int, int>
  9. #define pii pair<int, pair <int ,int> >
  10. #define pl pair<long long int , long long int>
  11. #define ll long long
  12. #define pll pair<ll,pair <ll,ll> >
  13. #define er erase
  14. #define mp make_pair
  15. #define cl clear
  16. #define maii map<int, int>
  17. #define Si(a) scanf("%d",&a)
  18. #define Slf(a) scanf("%lf",&a)
  19. #define Sull(a) scanf("%llu",&a)
  20. #define rep(i,k,n,l) for(int i = k; i < n; i=i+l)
  21. #define PI 3.14159265358979323846264
  22. #define ull unsigned long long
  23. #define MOD 100000007
  24. ull gcd(ull a, ull b)
  25. {
  26. if (a == 0)
  27. return b;
  28. return gcd(b%a, a);
  29. }
  30. double n,m,k,ra;
  31. double bs(double ans) {
  32. double hi = n;
  33. double lo = 1/ans;
  34. //cout << "hi/lo = " << hi/lo << endl;
  35. while((hi/lo) > 1.00000001) {
  36. double mid = (lo+(hi-lo)/2);
  37. //cout << "hi/lo = " << hi/lo << endl;
  38. //cout << "lo = " << lo << " " << hi << endl;
  39. //cout << "ans = " << ans <<" and square = " << mid/n << endl;
  40. double tmp = mid/n;
  41. double k = tmp/n;
  42. if(mid/n <= ans) {
  43. //cout << "mid = " << mid*mid << endl;
  44. lo = mid;
  45. }
  46. else {
  47. hi = mid-0.00000001;
  48. }
  49. }
  50. //cout << "lo " << lo << endl;
  51. return lo;
  52. }
  53.  
  54. int main() {
  55. //freopen("/home/nalin/Desktop/codes/input.txt","r", stdin);
  56. int t,lt = 1;
  57.  
  58. Si(t);
  59. while(lt <= t) {
  60. Slf(n);Slf(m);Slf(k);Slf(ra);
  61. double ans = (ra/(ra+1));
  62. //cout << "ans = " << ans << endl;
  63. //cout << "ra = " << sqrt(ans) << endl;
  64. double findsqrt =bs(sqrt(ans));
  65. //cout << bs(ra) << endl;
  66. double fa = findsqrt;
  67. printf("Case %d: %0.6lf\n",lt ,fa);
  68. lt++;
  69. }
  70. }
Success #stdin #stdout 0s 3464KB
stdin
4
100 100 100 2
10 12 14 1
7 8 9 10
8.134 9.098 7.123 5.10
stdout
Case 1: 81.649658
Case 2: 7.071068
Case 3: 6.674238
Case 4: 7.437455