Advertisement
Guest User

Untitled

a guest
Oct 4th, 2022
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.40 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4.  
  5. template <typename T>
  6. std::ostream & operator << (std::ostream & os, const std::vector<T> & vec);
  7. template <typename T>
  8. std::ostream & operator << (std::ostream & os, const std::set<T> & vec);
  9. template <typename T>
  10. std::ostream & operator << (std::ostream & os, const std::unordered_set<T> & vec);
  11. template <typename T>
  12. std::ostream & operator << (std::ostream & os, const std::multiset<T> & vec);
  13. template <typename T>
  14. std::ostream & operator << (std::ostream & os, const std::unordered_multiset<T> & vec);
  15. template<typename T1, typename T2>
  16. std::ostream & operator << (std::ostream & os, const std::pair<T1,T2> & p);
  17. template<typename T1, typename T2>
  18. std::ostream & operator << (std::ostream & os, const std::map<T1,T2> & p);
  19. template<typename T1, typename T2>
  20. std::ostream & operator << (std::ostream & os, const std::unordered_map<T1,T2> & p);
  21. template <typename T>
  22. std::ostream & operator << (std::ostream & os, const std::vector<T> & vec){
  23.     os<<"{";
  24.     for(auto elem : vec)
  25.         os<<elem<<",";
  26.     os<<"}";
  27.     return os;
  28. }
  29. template <typename T>
  30. std::ostream & operator << (std::ostream & os, const std::set<T> & vec){
  31.     os<<"{";
  32.     for(auto elem : vec)
  33.         os<<elem<<",";
  34.     os<<"}";
  35.     return os;
  36. }
  37. template <typename T>
  38. std::ostream & operator << (std::ostream & os, const std::unordered_set<T> & vec){
  39.     os<<"{";
  40.     for(auto elem : vec)
  41.         os<<elem<<",";
  42.     os<<"}";
  43.     return os;
  44. }
  45. template <typename T>
  46. std::ostream & operator << (std::ostream & os, const std::multiset<T> & vec){
  47.     os<<"{";
  48.     for(auto elem : vec)
  49.         os<<elem<<",";
  50.     os<<"}";
  51.     return os;
  52. }
  53. template <typename T>
  54. std::ostream & operator << (std::ostream & os, const std::unordered_multiset<T> & vec){
  55.     os<<"{";
  56.     for(auto elem : vec)
  57.         os<<elem<<",";
  58.     os<<"}";
  59.     return os;
  60. }
  61. template<typename T1, typename T2>
  62. std::ostream & operator << (std::ostream & os, const std::pair<T1,T2> & p){
  63.     os<<"{"<<p.first<<","<<p.second<<"}";
  64.     return os;
  65. }
  66. template<typename T1, typename T2>
  67. std::ostream & operator << (std::ostream & os, const std::map<T1,T2> & p){
  68.     os<<"{";
  69.     for(auto x: p)
  70.         os<<x.first<<"->"<<x.second<<", ";
  71.     os<<"}";
  72.     return os;
  73. }
  74. template<typename T1, typename T2>
  75. std::ostream & operator << (std::ostream & os, const std::unordered_map<T1,T2> & p){
  76.     os<<"{";
  77.     for(auto x: p)
  78.         os<<x.first<<"->"<<x.second<<", ";
  79.     os<<"}";
  80.     return os;
  81. }
  82. /*-------------------------------------------------------------------------------------------------------------------------------------*/
  83. #define t1(x)             cerr<<#x<<"="<<x<<endl
  84. #define t2(x, y)          cerr<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
  85. #define t3(x, y, z)       cerr<<#x<<"=" <<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl
  86. #define t4(a,b,c,d)       cerr<<#a<<"="<<a<<" "<<#b<<"="<<b<<" "<<#c<<"="<<c<<" "<<#d<<"="<<d<<endl
  87. #define t5(a,b,c,d,e)     cerr<<#a<<"="<<a<<" "<<#b<<"="<<b<<" "<<#c<<"="<<c<<" "<<#d<<"="<<d<<" "<<#e<<"="<<e<<endl
  88. #define t6(a,b,c,d,e,f)   cerr<<#a<<"="<<a<<" "<<#b<<"="<<b<<" "<<#c<<"="<<c<<" "<<#d<<"="<<d<<" "<<#e<<"="<<e<<" "<<#f<<"="<<f<<endl
  89. #define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
  90. #ifndef ONLINE_JUDGE
  91. #define tr(...) GET_MACRO(__VA_ARGS__,t6,t5, t4, t3, t2, t1)(__VA_ARGS__)
  92. #else
  93. #define tr(...)
  94. #endif
  95. /*-------------------------------------------------------------------------------------------------------------------------------------*/
  96. #define __ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
  97. #define fastio() ios::sync_with_stdio(0);cin.tie(0)
  98. #define MEMS(x,t) memset(x,t,sizeof(x));
  99. mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
  100. /*-------------------------------------------------------------------------------------------------------------------------------------*/
  101. // #define MOD 1000000007
  102. // #define MOD 998244353
  103. #define endl "\n"
  104. #define int long long
  105. #define inf 1e18
  106. #define ld long double
  107. /*-------------------------------------------------------------------------------------------------------------------------------------*/
  108.  
  109. ld dist(int x, int y)
  110. {
  111.     return sqrtl(x*x + y*y);
  112. }
  113.  
  114. int same_side(int px, int qx, int X)
  115. {
  116.     return min(px + qx, 2*X - px - qx);
  117. }
  118. int opp_side(int px, int qx, int X)
  119. {
  120.     return min(X + px - qx, X + qx - px);
  121. }
  122.  
  123. ld get_val(int X, int Y, int n, pair<int,int> p, pair<int,int> q, int cx, int cy, int parity)
  124. {
  125.     ld ans = inf;
  126.     ld approx_a = ((long double)(X*X - X*cx - Y*Y + Y*Y*n + Y*cy))/(X*X + Y*Y);
  127.     tr(approx_a, parity);
  128.     for(int a = approx_a - 50; a <= approx_a + 50; a ++)
  129.     {
  130.         int b = n - a;
  131.         if(min(a, b) < 0 or max(a, b) > n or a%2 != parity)
  132.             continue;
  133.         ans = min(ans, dist((a-1)*X + cx,  (b-1)*Y + cy));
  134.     }
  135.     return ans;
  136. }
  137. ld solve(int X, int Y, int n, pair<int,int> p, pair<int,int> q)
  138. {
  139.     if(n == 0){
  140.         return dist(p.first - q.first, p.second - q.second);
  141.     }
  142.  
  143.     ld ans = inf;
  144.  
  145.     {//a = 0
  146.         int cy = 0;
  147.         if(n%2)
  148.             cy = same_side(p.second, q.second, Y);
  149.         else
  150.             cy = opp_side(p.second, q.second, Y);
  151.  
  152.         ans = min(ans, dist(p.first - q.first, (n-1)*Y + cy));
  153.         // tr(cy, ans);
  154.     }
  155.  
  156.     {// a is odd
  157.         int cx = same_side(p.first, q.first, X);
  158.         int cy = 0;
  159.         if(n%2)
  160.             cy = opp_side(p.second, q.second, Y);
  161.         else
  162.             cy = same_side(p.second, q.second, Y);
  163.  
  164.         ans = min(ans, get_val(X,Y,n,p,q,cx,cy,1));
  165.        
  166.     }
  167.     {// a is even
  168.         int cx = opp_side(p.first, q.first, X);
  169.         int cy = 0;
  170.         if(n%2)
  171.             cy = same_side(p.second, q.second, Y);
  172.         else
  173.             cy = opp_side(p.second, q.second, Y);
  174.  
  175.         ans = min(ans, get_val(X,Y,n,p,q,cx,cy,0));
  176.     }
  177.     // tr(ans);
  178.     return ans;
  179.  
  180. }
  181. signed main()
  182. {
  183.     fastio();
  184.     int t;
  185.     cin>>t;
  186.     while(t--)
  187.     {
  188.         int X, Y, n;
  189.         cin>>X>>Y>>n;
  190.  
  191.         pair<int,int> p, q;
  192.         cin>>p.first>>p.second;
  193.         cin>>q.first>>q.second;
  194.  
  195.        
  196.         cout<<fixed<<setprecision(10);
  197.        
  198.  
  199.         ld ans = inf;
  200.         ans = min(ans, solve(X, Y, n, p, q));
  201.        
  202.         swap(X, Y);swap(p.first,p.second);swap(q.first,q.second);
  203.         ans = min(ans, solve(X, Y, n, p, q));
  204.  
  205.         cout<<ans<<endl;
  206.  
  207.     }
  208. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement