fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int t;
  6. double x1, y1, x2, y2, x3, t0, t1, t2, r;
  7. scanf("%d", &t);
  8. while(t--) {
  9. scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
  10. if(fabsl(x1 - x2) < 1e-9) {
  11. printf("%.9lf\n", log(y2) - log(y1));
  12. continue;
  13. }
  14. if(x1 > x2 + 1e-9)
  15. swap(x1, x2);
  16. if(y1 > y2 + 1e-9)
  17. swap(y1, y2);
  18. t0 = atan((y2 - y1) / (x2 - x1));
  19. x3 = ((y1 + y2) * tan(t0) + (x1 + x2)) / 2;
  20. t1 = atan(y1 / (x3 - x1));
  21. if(t1 < -1e-9)
  22. t1 += M_PI;
  23. t2 = atan(y2 / (x3 - x2));
  24. if(t2 < -1e-9)
  25. t2 += M_PI;
  26. r = log(fabsl(1 / sin(t2) - 1 / tan(t2)));
  27. r -= log(fabsl(1 / sin(t1) - 1 / tan(t1)));
  28. printf("%.9lf\n", r);
  29. }
  30. return 0;
  31. }
Success #stdin #stdout 0.01s 5292KB
stdin
2
3 7 8 2
123 456 789 10
stdout
1.683757232
4.962046997