fork download
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. double downhillLength(int h, int r) {
  7. double ratio = (double)h / r;
  8. double downhill = sqrt(2 * r * h - h * h);
  9. return downhill;
  10. }
  11.  
  12. int main() {
  13. int t;
  14. cin >> t;
  15.  
  16. for (int i = 0; i < t; ++i) {
  17. int h, r;
  18. cin >> h >> r;
  19.  
  20. // Kiểm tra điều kiện hợp lệ
  21. if (h <= r) {
  22. cout << -1 << endl;
  23. } else {
  24. double result = downhillLength(h, r);
  25. cout << fixed << result << endl;
  26. }
  27. }
  28.  
  29. return 0;
  30. }
  31.  
Success #stdin #stdout 0s 5292KB
stdin
Standard input is empty
stdout
Standard output is empty