Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define INF 999999999
  3. using namespace std;
  4.  
  5. double dist(pair<double, double> a, pair<double, double> b){
  6. return sqrt((a.first-b.first)*(a.first-b.first)+(a.second-b.second)*(a.second-b.second));
  7. }
  8.  
  9. pair<double, double> a, b;
  10. int v1, v2;
  11. double mindist, ld, rd;
  12.  
  13. void binary(int l, int r){
  14. int m1=l+(r-l)/3;
  15. int m2=l+2*(r-l)/3;
  16. if(l>=r)return;
  17. double md1=dist(a, make_pair(m1, 0))/v1+dist(b, make_pair(m1, 0))/v2;
  18. double md2=dist(a, make_pair(m2, 0))/v1+dist(b, make_pair(m2, 0))/v2;
  19. if(md1<mindist)mindist=md1;
  20. if(md1<md2){
  21. if(ld<m2)binary(l, m1);
  22. else binary(m1, m2);
  23. }
  24. else if(md1<rd)binary(m1, m2);
  25. else binary(m2, r);
  26. }
  27.  
  28. int main()
  29. {
  30. int t;
  31. scanf("%d", &t);
  32. for(int i=0; i<t; i++){
  33. int xx, xx_, yy, yy_;
  34. scanf("%d %d %d %d %d %d", &xx, &yy, &xx_, &yy_, &v1, &v2);
  35. a=make_pair(xx, yy), b=make_pair(xx_, yy_);
  36. if(a.first==b.first){
  37. cout<<fixed<<setprecision(5)<<b.second/v2-a.second/v1<<endl;
  38. }
  39. else{
  40. int lx=a.first, rx=b.first;
  41. if(lx>rx)swap(lx, rx);
  42. ld=dist(a, make_pair(lx, 0))/v1+dist(b, make_pair(lx, 0))/v2;
  43. rd=dist(a, make_pair(rx, 0))/v1+dist(b, make_pair(rx, 0))/v2;
  44. mindist=min(ld, rd);
  45. binary(lx, rx);
  46. cout<<fixed<<setprecision(5)<<mindist<<endl;
  47. }
  48. }
  49.  
  50.  
  51.  
  52. return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement