Untitled
#include<bits/stdc++.h> using namespace std; #define ll long long #define nl "\n" #define YES cout << "YES\n" #define NO cout << "NO\n" #define pb push_back #define llmx LONG_LONG_MAX #define llmn LONG_LONG_MIN #define mod 1000000007 const int N = 1e5 + 7; const int INF = 1e9 + 10; bool predicate(double mid, ll x1, ll y1, ll x2, ll y2, ll ww, ll hh, ll w, ll h) { y1 -= mid; y2 -= mid; ll rem_up = h - y2; ll rem_down = y1 - 0; if (rem_up >= hh || rem_down >= hh) return true; y1 += mid * 2; y2 += mid * 2; ll rem_up2 = h - y2; ll rem_down2 = y1 - 0; if (rem_up2 >= hh || rem_down2 >= hh) return true; y1 -= mid; y2 -= mid; x1 -= mid; x2 -= mid; ll rem_right = w - x2; ll rem_left = x1 - 0; if (rem_right >= ww || rem_left >= ww) return true; x1 += mid * 2; x2 += mid * 2; ll rem_right2 = w - x2; ll rem_left2 = x1 - 0; if (rem_right2 >= ww || rem_left2 >= ww) return true; return false; } void solve(){ ll w, h; cin >> w >> h; ll x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; ll ww, hh; cin >> ww >> hh; double l = 0; double r = 1e8; double ans = -1; while (r - l > 1e-6) { double mid = l + (r - l) / 2; if (predicate(mid, x1, y1, x2, y2, ww, hh, w, h)) { ans = mid; r = mid - 1; } else { l = mid + 1; } } cout << ans << nl; } /* Hey you should check this out * int overflow, array bounds * reset global array and variable * look for special cases (n=1?) * do something instead of nothing and stay organized * bruteforce to find pattern * DON'T GET STUCK ON ONE APPROACH * Think the problem backwards * In practice time don't see failing test case */ signed main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin >> t; while(t--) { solve(); } return 0; }
Leave a Comment