Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- template <typename T>
- std::ostream & operator << (std::ostream & os, const std::vector<T> & vec);
- template <typename T>
- std::ostream & operator << (std::ostream & os, const std::set<T> & vec);
- template <typename T>
- std::ostream & operator << (std::ostream & os, const std::unordered_set<T> & vec);
- template <typename T>
- std::ostream & operator << (std::ostream & os, const std::multiset<T> & vec);
- template <typename T>
- std::ostream & operator << (std::ostream & os, const std::unordered_multiset<T> & vec);
- template<typename T1, typename T2>
- std::ostream & operator << (std::ostream & os, const std::pair<T1,T2> & p);
- template<typename T1, typename T2>
- std::ostream & operator << (std::ostream & os, const std::map<T1,T2> & p);
- template<typename T1, typename T2>
- std::ostream & operator << (std::ostream & os, const std::unordered_map<T1,T2> & p);
- template <typename T>
- std::ostream & operator << (std::ostream & os, const std::vector<T> & vec){
- os<<"{";
- for(auto elem : vec)
- os<<elem<<",";
- os<<"}";
- return os;
- }
- template <typename T>
- std::ostream & operator << (std::ostream & os, const std::set<T> & vec){
- os<<"{";
- for(auto elem : vec)
- os<<elem<<",";
- os<<"}";
- return os;
- }
- template <typename T>
- std::ostream & operator << (std::ostream & os, const std::unordered_set<T> & vec){
- os<<"{";
- for(auto elem : vec)
- os<<elem<<",";
- os<<"}";
- return os;
- }
- template <typename T>
- std::ostream & operator << (std::ostream & os, const std::multiset<T> & vec){
- os<<"{";
- for(auto elem : vec)
- os<<elem<<",";
- os<<"}";
- return os;
- }
- template <typename T>
- std::ostream & operator << (std::ostream & os, const std::unordered_multiset<T> & vec){
- os<<"{";
- for(auto elem : vec)
- os<<elem<<",";
- os<<"}";
- return os;
- }
- template<typename T1, typename T2>
- std::ostream & operator << (std::ostream & os, const std::pair<T1,T2> & p){
- os<<"{"<<p.first<<","<<p.second<<"}";
- return os;
- }
- template<typename T1, typename T2>
- std::ostream & operator << (std::ostream & os, const std::map<T1,T2> & p){
- os<<"{";
- for(auto x: p)
- os<<x.first<<"->"<<x.second<<", ";
- os<<"}";
- return os;
- }
- template<typename T1, typename T2>
- std::ostream & operator << (std::ostream & os, const std::unordered_map<T1,T2> & p){
- os<<"{";
- for(auto x: p)
- os<<x.first<<"->"<<x.second<<", ";
- os<<"}";
- return os;
- }
- /*-------------------------------------------------------------------------------------------------------------------------------------*/
- #define t1(x) cerr<<#x<<"="<<x<<endl
- #define t2(x, y) cerr<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
- #define t3(x, y, z) cerr<<#x<<"=" <<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl
- #define t4(a,b,c,d) cerr<<#a<<"="<<a<<" "<<#b<<"="<<b<<" "<<#c<<"="<<c<<" "<<#d<<"="<<d<<endl
- #define t5(a,b,c,d,e) cerr<<#a<<"="<<a<<" "<<#b<<"="<<b<<" "<<#c<<"="<<c<<" "<<#d<<"="<<d<<" "<<#e<<"="<<e<<endl
- #define t6(a,b,c,d,e,f) cerr<<#a<<"="<<a<<" "<<#b<<"="<<b<<" "<<#c<<"="<<c<<" "<<#d<<"="<<d<<" "<<#e<<"="<<e<<" "<<#f<<"="<<f<<endl
- #define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
- #ifndef ONLINE_JUDGE
- #define tr(...) GET_MACRO(__VA_ARGS__,t6,t5, t4, t3, t2, t1)(__VA_ARGS__)
- #else
- #define tr(...)
- #endif
- /*-------------------------------------------------------------------------------------------------------------------------------------*/
- #define __ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
- #define fastio() ios::sync_with_stdio(0);cin.tie(0)
- #define MEMS(x,t) memset(x,t,sizeof(x));
- mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
- /*-------------------------------------------------------------------------------------------------------------------------------------*/
- // #define MOD 1000000007
- // #define MOD 998244353
- #define endl "\n"
- #define int long long
- #define inf 1e18
- #define ld long double
- /*-------------------------------------------------------------------------------------------------------------------------------------*/
- ld dist(int x, int y)
- {
- return sqrtl(x*x + y*y);
- }
- int same_side(int px, int qx, int X)
- {
- return min(px + qx, 2*X - px - qx);
- }
- int opp_side(int px, int qx, int X)
- {
- return min(X + px - qx, X + qx - px);
- }
- ld get_val(int X, int Y, int n, pair<int,int> p, pair<int,int> q, int cx, int cy, int parity)
- {
- ld ans = inf;
- ld approx_a = ((long double)(X*X - X*cx - Y*Y + Y*Y*n + Y*cy))/(X*X + Y*Y);
- tr(approx_a, parity);
- for(int a = approx_a - 50; a <= approx_a + 50; a ++)
- {
- int b = n - a;
- if(min(a, b) < 0 or max(a, b) > n or a%2 != parity)
- continue;
- ans = min(ans, dist((a-1)*X + cx, (b-1)*Y + cy));
- }
- return ans;
- }
- ld solve(int X, int Y, int n, pair<int,int> p, pair<int,int> q)
- {
- if(n == 0){
- return dist(p.first - q.first, p.second - q.second);
- }
- ld ans = inf;
- {//a = 0
- int cy = 0;
- if(n%2)
- cy = same_side(p.second, q.second, Y);
- else
- cy = opp_side(p.second, q.second, Y);
- ans = min(ans, dist(p.first - q.first, (n-1)*Y + cy));
- // tr(cy, ans);
- }
- {// a is odd
- int cx = same_side(p.first, q.first, X);
- int cy = 0;
- if(n%2)
- cy = opp_side(p.second, q.second, Y);
- else
- cy = same_side(p.second, q.second, Y);
- ans = min(ans, get_val(X,Y,n,p,q,cx,cy,1));
- }
- {// a is even
- int cx = opp_side(p.first, q.first, X);
- int cy = 0;
- if(n%2)
- cy = same_side(p.second, q.second, Y);
- else
- cy = opp_side(p.second, q.second, Y);
- ans = min(ans, get_val(X,Y,n,p,q,cx,cy,0));
- }
- // tr(ans);
- return ans;
- }
- signed main()
- {
- fastio();
- int t;
- cin>>t;
- while(t--)
- {
- int X, Y, n;
- cin>>X>>Y>>n;
- pair<int,int> p, q;
- cin>>p.first>>p.second;
- cin>>q.first>>q.second;
- cout<<fixed<<setprecision(10);
- ld ans = inf;
- ans = min(ans, solve(X, Y, n, p, q));
- swap(X, Y);swap(p.first,p.second);swap(q.first,q.second);
- ans = min(ans, solve(X, Y, n, p, q));
- cout<<ans<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement