Advertisement
Farjana_akter

Untitled

May 31st, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. double ax,bx,cx,dx,ay,by,cy,dy;
  4.  
  5. double dis(double mid)
  6. {
  7. double x1=ax+(bx-ax)*mid;
  8. double y1=ay+(by-ay)*mid;
  9. double x2=cx+(dx-cx)*mid;
  10. double y2=cy+(dy-cy)*mid;
  11.  
  12. double d=sqrt(((x2-x1)*(x2-x1))+((y2-y1)*(y2-y1)));
  13. return d;
  14. }
  15.  
  16. int main()
  17. {
  18. int t,i,j;
  19. double hi,lo,mid1,mid2;
  20. cin>>t;
  21. for(i=1;i<=t;i++)
  22. {
  23. cin>>ax>>ay>>bx>>by>>cx>>cy>>dx>>dy;
  24. hi=1.0,lo=0.0;
  25. for(j=1;j<=43;j++)
  26. {
  27. mid1=(lo*2.0+hi)/3.0;
  28. mid2=(lo+hi*2.0)/3.0;
  29. if(dis(mid1)>dis(mid2))
  30. lo=mid1;
  31. else
  32. hi=mid2;
  33. }
  34. double ans= dis((lo+hi)/2.0);
  35. printf("Case %d: %.10lf\n",i,ans);
  36. }
  37. return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement