text
stringlengths
49
983k
#include <bits/stdc++.h> using namespace std; double w, h, rw, rh; void get(double w, double h) { double best_a = 0; double th = 1, tw = 0; while (th <= h) { int lo = 1, hi = w; while (lo <= hi) { double mid = (lo + hi) / 2; double v = th / mid; if (v < 0.8 - 1e-9) { hi = mid - 1; } else if (v > 1.25) { lo = mid + 1; } else { if (th * mid > best_a) { rh = th; rw = mid; best_a = th * mid; } lo = mid + 1; } } th *= 2.; } tw = 1, th = 0; while (tw <= w) { int lo = 1, hi = h; while (lo <= hi) { double mid = (lo + hi) / 2; if (mid / tw < 0.8 - 1e-9) { lo = mid + 1; } else if (mid / tw > 1.25) { hi = mid - 1; } else { if (mid * tw >= best_a) { rh = mid; rw = tw; best_a = mid * tw; } else if (mid * tw == best_a) { if (mid > rh) { rh = mid; tw = tw; } } lo = mid + 1; } } tw *= 2; } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> h >> w; get(w, h); cout << (int)rh << " " << (int)rw << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; const int INF = 0x7f7f7f7f; const int MAXN = 1e6 + 111; long long ansh = 0, answ = 0; void solve1(long long a, long long b) { long long base = 1; while (base <= a) base *= 2; base /= 2; long long mx = base * 1.25, mi = ceil(base * 0.8); if (mx <= b && base * mx >= ansh * answ) { if (base * mx > ansh * answ) { ansh = base, answ = mx; } else if (base > ansh) { ansh = base, answ = mx; } } else if (mi <= b && base * b >= ansh * answ) { if (base * b > ansh * answ) { ansh = base, answ = b; } else if (base > ansh) { ansh = base, answ = b; } } else if (mi > b) { solve1(base / 2, b); } } void solve2(long long a, long long b) { long long base = 1; while (base < a) base *= 2; base /= 2; long long mx = base * 1.25, mi = ceil(base * 0.8); if (mx <= b && base * mx >= ansh * answ) { if (base * mx > ansh * answ) { ansh = mx, answ = base; } else if (mx > ansh) { ansh = mx, answ = base; } } else if (mi <= b && base * b >= ansh * answ) { if (base * b > ansh * answ) { ansh = b, answ = base; } else if (b > ansh) { ansh = b, answ = base; } } else if (mi > b) { solve2(base / 2, b); } } int main() { long long h, w; while (cin >> h >> w) { solve1(h, w); solve2(w, h); cout << ansh << ' ' << answ << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; long long int assign(double d) { long long int ans = d; if (abs(abs(d - ans) - 1) < 0.00000000001) return ans + 1; return ans; } long long int power(long long int b, long long int n) { long long int ans = 1; for (int i = 0; i < n; i++) ans *= b; return ans; } int main() { ios ::sync_with_stdio(false); long long int h, w; cin >> h >> w; long long int mxH = 0, mxW = 0; long long int area = 0; for (int i = 0; power(2, i) <= h; i++) { long long int hT = power(2, i); double w1, w2; long long int wF; w1 = hT / 0.8; w2 = hT / 1.25; if (w1 <= w && w2 <= w) wF = assign(w1); else if (w2 <= w && w1 > w) wF = assign(w); else continue; if ((area < hT * wF) || (area == hT * wF && hT > mxH)) { area = hT * wF; mxH = hT; mxW = wF; } } for (int i = 0; power(2, i) <= w && 1; i++) { long long int wT = power(2, i); double h1, h2; long long int hF; h2 = wT * 0.8; h1 = wT * 1.25; if (h1 <= h && h2 <= h) hF = assign(h1); else if (h2 <= h && h1 > h) hF = assign(h); else continue; if ((area < wT * hF) || (area == hF * wT && hF > mxH)) { mxH = hF; mxW = wT; } } cout << mxH << " " << mxW; return 0; }
#include <bits/stdc++.h> using namespace std; long long int modexp(long long int a, long long int n) { long long int r = 1; while (n) { if (n & 1) r = (r * a) % 1000000007; a = (a * a) % 1000000007; n >>= 1; } return r; } bool cmpfunc(const pair<int, int> &u, const pair<int, int> &v) { if (u.first < v.first) return true; return false; } bool compare(pair<long long int, long long int> p, pair<long long int, long long int> q) { if (p.first < q.first) return true; else if (p.first == q.first) { if (p.second < q.second) return true; return false; } return false; } void solve() { long long int h, w; cin >> h >> w; long long int ans_h = 0, ans_W = 0; for (int i = 0; i < 31; i++) { long long int h1 = (1ll << i); long long int w1 = min(h1 * 1.25, w + 0.0); if (h1 * 1.0 / w1 > 1.25 + 0.001 || h1 * 1.0 / w1 < 0.8 - 0.001) continue; if (h1 > h || w1 > w) continue; if (h1 * w1 > ans_h * ans_W || (h1 * w1 == ans_h * ans_W && h1 > ans_h)) ans_h = h1, ans_W = w1; } for (int i = 0; i < 31; i++) { long long int w1 = (1 << i); long long int h1 = min(w1 * 1.25, h + 0.0); if (h1 * 1.0 / w1 > 1.25 + 0.001 || h1 * 1.0 / w1 < 0.8 - 0.001) continue; if (w1 > w || h1 > h) continue; if (h1 * w1 > ans_h * ans_W || (h1 * w1 == ans_h * ans_W && h1 > ans_h)) ans_h = h1, ans_W = w1; } cout << ans_h << ' ' << ans_W; return; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int t; t = 1; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; long long h, w, a = 1, m, n; bool flag; int main() { cin >> h >> w; while (a << 1 <= h && a << 1 <= w) a <<= 1; m = min(h, a * 5 / 4), n = min(w, a * 5 / 4); if (m >= n) cout << m << ' ' << a; else cout << a << ' ' << n; return 0; }
#include <bits/stdc++.h> int IntMaxVal = (int)1e20; int IntMinVal = (int)-1e20; long long LongMaxVal = (long long)1e20; long long LongMinVal = (long long)-1e20; using namespace std; template <typename T> struct argument_type; template <typename T, typename U> struct argument_type<T(U)> {}; template <typename T1, typename T2> istream& operator>>(istream& is, pair<T1, T2>& s) { is >> s.first >> s.second; return is; } template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { for (int i = 0; i < v.size(); i++) os << v[i] << ' '; os << endl; return os; } template <typename T1, typename T2> ostream& operator<<(ostream& s, pair<T1, T2>& t) { s << t.first << ' ' << t.second; return s; } int main() { srand(time(NULL)); ios_base::sync_with_stdio(false); cin.tie(NULL); long long h; cin >> h; ; long long w; cin >> w; ; auto res = make_pair(0LL, make_pair(0LL, 0LL)); for (long long hi = 1; hi <= h; hi *= 2) { long long wi = 5 * hi / 4; { wi = min(wi, w); }; if (hi * 4 >= wi * 5) continue; { res = max(res, make_pair(hi * wi, make_pair(hi, wi))); }; } for (long long wi = 1; wi <= w; wi *= 2) { long long hi = 5 * wi / 4; { hi = min(hi, h); }; if (wi * 4 >= hi * 5) continue; { res = max(res, make_pair(hi * wi, make_pair(hi, wi))); }; } cout << res.second; }
#include <bits/stdc++.h> using namespace std; vector<long long> area(long long h, long long w) { long long p = log2(h); for (p; p >= 0; p--) { long long y = pow(2, p); long long a = ceil(y / 1.25), b = round(y / 0.8); if (w >= a && w <= b) { vector<long long> s = {y, w}; return s; } else if (b < w) { vector<long long> s = {y, b}; return s; } } vector<long long> s = {h, 0}; return s; } int main() { long long h, w; cin >> h >> w; vector<long long> a = area(h, w), b = area(w, h); if (a[0] * a[1] > b[0] * b[1]) { cout << a[0] << " " << a[1] << endl; } else if (a[0] * a[1] < b[0] * b[1]) { cout << b[1] << " " << b[0] << endl; } else { if (a[0] > b[1]) cout << a[0] << " " << a[1] << endl; else cout << b[1] << " " << b[0] << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; long long n, m, a, b, c, d; int main() { cin >> n >> m; if (n > m) { a = (1 << (long long)(log2(min(n, (long long)(m * 1.25))))); b = min((long long)(a * 1.25), m); d = (1 << (long long)(log2(m))); c = min((long long)(d * 1.25), n); } else if (n < m) { a = (1 << (long long)(log2(n))); b = min((long long)(a * 1.25), m); d = (1 << (long long)(log2(min((long long)(n * 1.25), m)))); c = min((long long)(d * 1.25), n); } else { a = (1 << (long long)(log2(n))); b = min((long long)(a * 1.25), m); d = (1 << (long long)(log2(m))); c = min((long long)(d * 1.25), n); } if (a * b > c * d) cout << a << " " << b << '\n'; else if (a * b < c * d) cout << c << " " << d << '\n'; else { if (a > c) cout << a << " " << b << '\n'; else cout << c << " " << d << '\n'; } }
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 100; const int INF = 0x3f3f3f3f; long long p[maxn]; int main() { p[0] = 1; for (int i = 1; i <= 32; ++i) { p[i] = p[i - 1] * 2; } long long n, h, w; while (cin >> h >> w) { int posh = upper_bound(p, p + 31, h) - p; long long ans = 0, ansh = 0, answ; for (int i = 0; i < posh; ++i) { long long hh = p[i]; long long w1 = (p[i] * 4 + 4) / 5; long long w2 = (p[i] * 5) / 4; if (w < w1) continue; if (w >= w1 && w <= w2) { if (w * hh >= ans) { ans = w * hh; ansh = hh; answ = w; } } else if (w > w2) { if (w2 * hh >= ans) { ans = w2 * hh; ansh = hh; answ = w2; } } } int posw = upper_bound(p, p + 31, w) - p; for (int i = 0; i < posw; ++i) { long long ww = p[i]; long long h1 = (p[i] * 4 + 4) / 5; long long h2 = (p[i] * 5) / 4; if (h < h1) continue; if (h >= h1 && h <= h2) { if (h * ww >= ans) { ans = h * ww; ansh = h; answ = ww; } } else if (h > h2) { if (h2 * ww > ans || (h2 * ww == ans && h2 > ansh)) { ans = ww * h2; ansh = h2; answ = ww; } } } printf("%lld %lld\n", ansh, answ); } return 0; }
#include <bits/stdc++.h> using namespace std; bool check(long long x, long long y) { if (x < y) swap(x, y); return 4 * x <= 5 * y; } int main() { long long h, w; cin >> h >> w; long long height = 0, width = 0, area = 0; for (long long a = 1; a <= h; a *= 2) { long long b = min(w, (4 * a + 4) / 5); if (check(a, b) && (a * b > area || (a * b == area && a > height))) { height = a; width = b; area = a * b; } b = min(w, 5 * a / 4); if (check(a, b) && (a * b > area || (a * b == area && a > height))) { height = a; width = b; area = a * b; } } for (long long b = 1; b <= width; b *= 2) { long long a = min(h, 5 * b / 4); if (check(a, b) && (a * b > area || (a * b == area && a > height))) { height = a; width = b; area = a * b; } a = min(h, (4 * b + 4) / 5); if (check(a, b) && (a * b > area || (a * b == area && a > height))) { height = a; width = b; area = a * b; } } cout << height << " " << width << endl; }
#include <bits/stdc++.h> using namespace std; long long hmax = 0, wmax = 0; void case1(long long h, long long w) { long long hnew = 1; while (hnew <= h) hnew *= 2; hnew /= 2; double w1 = hnew * 0.8, w2 = hnew * 1.25; if (w < w1) return; if (w > w2) w = w2; if (hmax * wmax < hnew * w) { hmax = hnew; wmax = w; } else if (hmax * wmax == hnew * w && hmax < hnew) { hmax = hnew; wmax = w; } return; } void case2(long long h, long long w) { long long wnew = 1; while (wnew <= w) wnew *= 2; wnew /= 2; double h1 = wnew * 0.8, h2 = wnew * 1.25; if (h < h1) return; if (h > h2) h = h2; if (hmax * wmax < wnew * h) { hmax = h; wmax = wnew; } else if (hmax * wmax == wnew * h && hmax < h) { hmax = h; wmax = wnew; } return; } int main() { long long h, w; cin >> h >> w; case1(h, w); case2(h, w); cout << hmax << " " << wmax << endl; }
#include <bits/stdc++.h> using namespace std; long long h, w; long long gh, gw; void check(long long nh, long long nw) { if (4 * nw > 5 * nh) return; if (4 * nh > 5 * nw) return; if (nh * nw > gh * gw) { gh = nh; gw = nw; } if ((nh * nw == gh * gw) && (nh > gh)) { gh = nh; gw = nw; } } int main() { cin >> h >> w; for (long long i = 1; i <= h; i *= 2) { check(i, min(i * 5 / 4, w)); } for (long long i = 1; i <= w; i *= 2) { check(min(i * 5 / 4, h), i); } cout << gh << " " << gw << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long h, w, hh{}, ww{}; cin >> h >> w; for (int i = 0; (1 << i) <= h; ++i) { long long h1 = 1 << i; long long w_min = (4 * h1 + 4) / 5; long long w_max = min(w, (5 * h1) / 4); if (w_min <= w_max) { if (w_max * h1 > hh * ww) hh = h1, ww = w_max; else if (w_max * h1 == hh * ww && h1 > hh) hh = h1, ww = w_max; } } for (int i = 0; (1 << i) <= w; ++i) { long long w1 = 1 << i; long long h_min = (4 * w1 + 4) / 5; long long h_max = min(h, (5 * w1) / 4); if (h_min <= h_max) { if (w1 * h_max > hh * ww) hh = h_max, ww = w1; else if (w1 * h_max == hh * ww & h_max > hh) hh = h_max, ww = w1; } } cout << hh << ' ' << ww; return 0; }
#include <bits/stdc++.h> using namespace std; class TPL { public: long long h, w; TPL() {} TPL(long long h, long long w) : h(h), w(w) {} TPL& truncate() { if (4 * h > 5 * w) h = 5 * w / 4; if (4 * w > 5 * h) w = 5 * h / 4; return *this; } bool operator<(const TPL& rhs) const { if (h * w != rhs.h * rhs.w) return h * w < rhs.h * rhs.w; return h < rhs.h; } }; int main() { TPL a; scanf("%I64d%I64d", &a.h, &a.w); a.truncate(); a = max(TPL(1 << 31 - __builtin_clz(int(a.h)), a.w).truncate(), TPL(a.h, 1 << 31 - __builtin_clz(int(a.w))).truncate()); printf("%I64d %I64d\n", a.h, a.w); }
#include <bits/stdc++.h> using namespace std; struct Tpoint { double x, y; Tpoint() {} Tpoint(double _x, double _y) { x = _x; y = _y; } inline void read() { scanf("%lf%lf", &x, &y); } inline void show() { printf("%lf %lf\n", x, y); } inline double norm() { return sqrt(((x) * (x)) + ((y) * (y))); } }; inline Tpoint operator+(const Tpoint &a, const Tpoint &b) { return Tpoint(a.x + b.x, a.y + b.y); } inline Tpoint operator-(const Tpoint &a, const Tpoint &b) { return Tpoint(a.x - b.x, a.y - b.y); } inline Tpoint operator*(const Tpoint &a, const double &b) { return Tpoint(a.x * b, a.y * b); } inline Tpoint operator/(const Tpoint &a, const double &b) { return Tpoint(a.x / b, a.y / b); } inline double det(const Tpoint &a, const Tpoint &b) { return a.x * b.y - a.y * b.x; } inline double dot(const Tpoint &a, const Tpoint &b) { return a.x * b.x + a.y * b.y; } int main() { int h, w; scanf("%d%d", &h, &w); double lrate = 0.8, rrate = 1.25; long long big = 0; int ansh = 0, answ = 0; for (int width = 1; width <= w; width <<= 1) { long long hl = (long long)ceil(lrate * width); long long hr = (long long)floor(rrate * width); hl = max(hl, 1LL); hr = min(hr, (long long)h); if (hl <= hr) { long long area = width * hr; if (area > big || area == big && hr > ansh) { big = area; ansh = (int)hr; answ = width; } } } lrate = 1.0 / 1.25, rrate = 1.0 / 0.8; for (int width = 1; width <= h; width <<= 1) { long long hl = (long long)ceil(lrate * width); long long hr = (long long)floor(rrate * width); hl = max(hl, 1LL); hr = min(hr, (long long)w); if (hl <= hr) { long long area = width * hr; if (area > big || area == big && width > ansh) { big = area; ansh = width; answ = (int)hr; } } } printf("%d %d\n", ansh, answ); return 0; }
#include <bits/stdc++.h> using namespace std; long long h, w, a = 1, m, n; bool flag; int main() { ios::sync_with_stdio(0); cin >> h >> w; while (a << 1 <= h && a << 1 <= w) a <<= 1; m = min(h, a * 5 / 4), n = min(w, a * 5 / 4); if (m >= n) cout << m << ' ' << a; else cout << a << ' ' << n; return 0; }
#include <bits/stdc++.h> using namespace std; long long ts, h, w, s, l, maxsquare, maxh, maxw; int main() { scanf("%I64d%I64d", &h, &w); maxsquare = 0; maxh = 0; maxw = 0; for (ts = 0; ts < 31; ts++) { s = (long long)1 << ts; if (s > h) break; if (0.8 * s > w) continue; if (1.25 * s < w) l = floor(1.25 * s); if ((0.8 * s <= w) && (w <= 1.25 * s)) l = w; if ((s * l > maxsquare) || ((s * l == maxsquare) && (s > maxh))) { maxsquare = s * l; maxh = s; maxw = l; } } for (ts = 0; ts < 31; ts++) { l = (long long)1 << ts; if (l > w) break; if (0.8 * l > h) continue; if (1.25 * l < h) s = floor(1.25 * l); if ((0.8 * l <= h) && (h <= 1.25 * l)) s = h; if ((s * l > maxsquare) || ((s * l == maxsquare) && (s > maxh))) { maxsquare = s * l; maxh = s; maxw = l; } } printf("%I64d %I64d\n", maxh, maxw); return 0; }
#include <bits/stdc++.h> using namespace std; long long n, m, a, b, c, d; int main() { cin >> n >> m; if (n > m) { a = (1 << (long long)(log2(min(n, (long long)(m * 1.25))))); b = min((long long)(a * 1.25), m); d = (1 << (long long)(log2(m))); c = min((long long)(d * 1.25), n); } else if (n < m) { a = (1 << (long long)(log2(n))); b = min((long long)(a * 1.25), m); d = (1 << (long long)(log2(min((long long)(n * 1.25), m)))); c = min((long long)(d * 1.25), n); } else { a = (1 << (long long)(log2(n))); b = min((long long)(a * 1.25), m); d = (1 << (long long)(log2(m))); c = min((long long)(d * 1.25), n); } if (a * b > c * d) cout << a << " " << b << '\n'; else if (a * b < c * d) cout << c << " " << d << '\n'; else { if (a > c) cout << a << " " << b << '\n'; else cout << c << " " << d << '\n'; } }
#include <bits/stdc++.h> using namespace std; void read_file(bool outToFile = true) {} int BS(int lo, int hi, int cond) { hi++; while (lo != hi - 1) { int md = (lo + hi) / 2; if (md <= 125LL * cond / 100) lo = md; else hi = md; } return lo; } void debug(int i, int j) { printf("i = %d, j = %d\n", i, j); } void doit(int h, int w, int &ansH, int &ansW, bool turn) { for (int i = 1; i <= h; i *= 2) { int j; j = min(125LL * i / 100, 1LL * w); if (!(8LL * i <= 10LL * j && 100LL * j <= 125LL * i && j <= w)) continue; long long nw = 1LL * i * j, old = 1LL * ansH * ansW; if (turn) swap(i, j); if (nw > old || nw == old && i > ansH) ansH = i, ansW = j; if (turn) swap(i, j); } } int main() { read_file(); int h, w; while (scanf("%d %d\n", &h, &w) != EOF) { int ansH = 1, ansW = 1; doit(h, w, ansH, ansW, 0); doit(w, h, ansH, ansW, 1); printf("%d %d\n", ansH, ansW); } }
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int maxn = 1e5 + 15; bool judge(long long h, long long w) { if (h * 4 <= w * 5 && h * 5 >= w * 4) return true; return false; } int main() { ios::sync_with_stdio(false); long long h, w; cin >> h >> w; if (h * 4 > w * 5) h = 5 * w / 4; if (h * 5 < w * 4) w = 5 * h / 4; int oh = __builtin_popcount(h); int ow = __builtin_popcount(w); if (judge(h, w) && (oh == 1 || ow == 1)) cout << h << ' ' << w << endl; else { long long nh = 1 << 63 - __builtin_clzll(h); long long nw = 1 << 63 - __builtin_clzll(w); long long l = nw * 4 / 5, r = h; while (l <= r) { long long mid = l + r >> 1; if (judge(mid, nw)) l = mid + 1; else r = mid - 1; } long long nl = nh * 4 / 5, nr = w; while (nl <= nr) { long long mid = nl + nr >> 1; if (judge(nh, mid)) nl = mid + 1; else nr = mid - 1; } if (nh * nr > r * nw) cout << nh << ' ' << nr << endl; else cout << r << ' ' << nw << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; long long mul(long long a, long long b, long long p = 1000000007) { return ((a % p) * (b % p)) % p; } long long add(long long a, long long b, long long p = 1000000007) { return (a % p + b % p) % p; } void input(long long a[], long long sz) { for (long long i = 0; i < sz; i++) cin >> a[i]; } void print(long long a[], long long sz) { for (long long i = 0; i < sz; i++) { if (i == sz - 1) cout << a[i] << "\n"; else cout << a[i] << " "; } } long long maxr(long long a[], long long sz) { long long ma; for (long long i = 0; i < sz; i++) { if (i == 0) ma = a[i]; else if (a[i] > ma) ma = a[i]; } return ma; } long long minr(long long a[], long long sz) { long long mi; for (long long i = 0; i < sz; i++) { if (i == 0) mi = a[i]; else if (a[i] < mi) mi = a[i]; } return mi; } long long isprm(long long n) { if (n <= 1) return 0; if (n <= 3) return 1; if (n % 2 == 0 || n % 3 == 0) return 0; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return 0; return 1; } long long b_srch(long long arr[], long long l, long long r, long long x) { while (l <= r) { int m = l + (r - l) / 2; if (arr[m] == x) return m; if (arr[m] < x) l = m + 1; else r = m - 1; } return -1; } long long power(long long x, long long y, long long p) { long long res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } long long modInverse(long long n, long long p) { return power(n, p - 2, p); } long long nCrModPFermat(long long n, long long r, long long p) { if (r == 0) return 1; long long fac[n + 1]; fac[0] = 1; for (long long i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % p; return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; long long h, w, mh = 0, mw = 0, x = 0, y = 0; cin >> h >> w; long long p1 = log2(h), p2 = log2(w); for (long long i = p1; i >= 0; i--) { long long ht = pow(2, i); long long r = 1.25 * ht; long long l = ceil(0.8 * ht); if (w > r) mw = r; else if (w >= l) mw = w; if (mw != 0) { mh = ht; break; } } for (long long i = p2; i >= 0; i--) { long long ht = pow(2, i); long long r = 1.25 * ht; long long l = ceil(0.8 * ht); if (h > r) x = r; else if (h >= l) x = h; if (x != 0) { y = ht; break; } } long long ar1 = mh * mw, ar2 = x * y; if (ar1 > ar2) { cout << mh << " " << mw << "\n"; } else if (ar1 == ar2) { if (x > mh) cout << x << " " << y << "\n"; else cout << mh << " " << mw << "\n"; } else if (ar1 < ar2) { cout << x << " " << y << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; void solve() { int w, h; cin >> w >> h; pair<long long, long long> mn; for (long long i = 1; i <= w; i = i << 1) { long long ww = i; long long hh = min(h, (int)(i * 1.25)); if (hh < 0.8 * i) break; if (ww * hh > mn.first * mn.second || (ww * hh == mn.first * mn.second && ww > mn.first)) { mn = pair<long long, long long>(ww, hh); } } for (long long i = 1; i <= h; i = i << 1) { long long hh = i; long long ww = min(w, (int)(i * 1.25)); if (ww < 0.8 * i) break; if (ww * hh > mn.first * mn.second || (ww * hh == mn.first * mn.second && ww > mn.first)) { mn = pair<long long, long long>(ww, hh); } } cout << mn.first << ' ' << mn.second; } int main() { solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int l, w; cin >> l >> w; int k = 1; while (2 * k <= l && 2 * k <= w) { k = k * 2; } int bl = min(l, int(1.25 * k)); int bw = min(w, int(1.25 * k)); if (bl >= bw) { cout << bl << " " << k << endl; } else cout << k << " " << bw << endl; return 0; }
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:64000000") using namespace std; int main() { long long a, n = 0, m = 0, h, s, a1[1 << 7], a2[1 << 7]; cin >> h >> s; long long s1 = s; long long h1 = h; long long k = 1; while ((1 << n) < h) ++n; if (n) --n; while ((1 << m) < s) ++m; if (m) --m; if (((!(h & (h - 1))) || (!(s & (s - 1)))) && h * 100 <= 125 * s && h * 100 >= 80 * s) { cout << h << " " << s; return 0; } h = 1 << n; s = 1 << m; int mxh, mxs; { { if (h * 100 <= 125 * s) { while (h * 100 <= 125 * s && h * 100 >= 80 * s) { if (h == h1) break; ++h; if (!(h * 100 <= 125 * s && h * 100 >= 80 * s)) { --h; break; } } } mxh = h; h = 1 << n; if (h * 100 >= 80 * s) { while (h * 100 <= 125 * s && h * 100 >= 80 * s) { if (s == s1) break; ++s; if (!(h * 100 <= 125 * s && h * 100 >= 80 * s)) { --s; break; } } } mxs = s; s = 1 << m; long long p1 = (long long)mxh * (long long)s; long long p2 = (long long)mxs * (long long)h; if (p1 >= p2) { cout << mxh << " " << s; return 0; } else { cout << h << " " << mxs; return 0; } } } cout << h << " " << s; return 0; }
#include <bits/stdc++.h> using namespace std; void testCase() { double height, width; cin >> height >> width; int w = 1; while (w <= width && w <= height) w <<= 1; w >>= 1; int l = 1, r = max(height, width); int ans = 0; while (r >= l) { int mid = l + (r - l) / 2; double temp = (double(mid) / w); if (temp > 1.25) r = mid - 1; else if (temp < 0.8) l = mid + 1; else { ans = max(ans, mid); l = mid + 1; } } if (ans > height) { cout << w << ' ' << ans; return; } cout << ans << ' ' << w; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); testCase(); return 0; }
#include <bits/stdc++.h> using namespace std; int a, b, a0, a1, b0, b1; long long s0, s1; int main() { cin >> a >> b; a0 = min(int(log(double(a)) / log(2.)), int(log(1.25 * b) / log(2.))); a0 = 1 << a0; b0 = min(b, int(a0 / 0.8)); s0 = (long long)a0 * b0; b1 = min(int(log(double(b)) / log(2.)), int(log(a / 0.8) / log(2.))); b1 = 1 << b1; a1 = min(a, int(b1 * 1.25)); s1 = (long long)a1 * b1; if (s0 > s1 || (s0 == s1 && a0 > a1)) cout << a0 << ' ' << b0 << endl; else cout << a1 << ' ' << b1 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int const MaxSize = 5000 + 5; int const MOD = 1e9 + 7; long long h, w; int main() { ios_base::sync_with_stdio(false); cin >> h >> w; long long ansA = 0; ; int aH, aW; for (long long nH = 1; nH <= h; nH *= (long long)2) { long long wUp = min(w, (nH * (long long)5) / (long long)4); long long wLow = (nH * (long long)4) / (long long)5 + 1; if (wUp >= wLow && wUp * nH > ansA) { aH = nH; aW = wUp; ansA = wUp * nH; } } for (long long nW = 1; nW <= w; nW *= (long long)2) { long long hUp = min(h, (nW * (long long)5) / (long long)4); long long hLow = (nW * (long long)4) / (long long)5 + 1; if (hUp >= hLow && hUp * nW >= ansA) { if (hUp * nW == ansA && hUp < aH) { } else { aH = hUp; aW = nW; ansA = hUp * nW; } } } cout << aH << " " << aW; return 0; }
#include <bits/stdc++.h> using namespace std; long long r, h; long long ans(long long s) { long long i = 1, j = r, md, ok = -1; while (i <= j) { md = (i + j) / 2; double kk = ((double)md / (double)s); if (kk >= 0.8 && kk <= 1.25) { ok = md; i = md + 1; } else if (kk < 0.8) { i = md + 1; } else j = md - 1; } return ok; } long long anss(long long s) { long long i = 1, j = h, md, ok = -1; while (i <= j) { md = (i + j) / 2; double kk = ((double)md / (double)s); if (kk >= 0.8 && kk <= 1.25) { ok = md; i = md + 1; } else if (kk < 0.8) { i = md + 1; } else j = md - 1; } return ok; } int main() { long long p, l = 0, i, j, k; cin >> h >> r; for (i = 0; i < h; i++) { k = pow(2, i); if (k > h) break; if (ans(k) != -1) { p = k; l = ans(k); } } long long pp = 0, lll = 0; for (i = 0; i < r; i++) { k = pow(2, i); if (k > r) break; if (anss(k) != -1) { pp = anss(k); lll = k; } } if (p < pp && p * l <= pp * lll) { p = pp; l = lll; } cout << p << " " << l; }
#include <bits/stdc++.h> using namespace std; double w, h, tw, th, resw, resh; int main() { cin >> w >> h; for (th = 1; th <= h; th *= 2) { tw = min(int(1.25 * th), int(w)); if (tw / th >= 0.8 && tw * th > resw * resh) { resw = tw; resh = th; } } for (tw = 1; tw <= w; tw *= 2) { th = min(int(1.25 * tw), int(h)); if (th / tw >= 0.8 && tw * th > resw * resh) { resw = tw; resh = th; } } cout << int(resw) << ' ' << int(resh); }
#include <bits/stdc++.h> using namespace std; int main() { int h, w; cin >> h >> w; int bestH = -1, bestW = -1; for (int j = 1; j <= h; j *= 2) { int i = ((w <= j / 0.8) ? w : j / 0.8); if (j / (double)i < 0.8 || j / (double)i > 1.25) continue; if (bestH == -1) { bestH = j; bestW = i; } else if (i * 1LL * j >= bestH * 1LL * bestW && j > bestH) { bestH = j; bestW = i; } if (i * 1LL * j > bestH * 1LL * bestW) { bestH = j; bestW = i; } } for (int i = 1; i <= w; i *= 2) { int j = ((h <= i * 1.25) ? h : i * 1.25); if (j / (double)i < 0.8 || j / (double)i > 1.25) continue; if (bestH == -1) { bestH = j; bestW = i; } else if (i * 1LL * j >= bestH * 1LL * bestW && j > bestH) { bestH = j; bestW = i; } if (i * 1LL * j > bestH * 1LL * bestW) { bestH = j; bestW = i; } } cout << bestH << " " << bestW << endl; return 0; }
#include <bits/stdc++.h> using namespace std; void solve() { long long h, w; cin >> h >> w; long long pow2max = 1; while (2 * pow2max <= h && 2 * pow2max <= w) pow2max *= 2; long long hmax = min(h, (long long)(1.25 * pow2max)); long long wmax = min(w, (long long)(1.25 * pow2max)); if (hmax >= wmax) cout << hmax << " " << pow2max; else cout << pow2max << " " << wmax; return; } signed main() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); long long t = 1; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { double w, h, w1 = 1, h1 = 1, w2, h2; cin >> h >> w; for (int x = 0; (1ll << x) <= h; x++) { h2 = (1 << x); w2 = ceil(h2 / 1.25 - 1e-9); if (w2 < floor(h2 / .8 + 1e-9) + 1e-9 && w2 < w + 1e-9) { w2 = min(w, floor(h2 / .8 + 1e-9)); if (w2 * h2 > w1 * h1) { w1 = w2; h1 = h2; } else if (abs(w1 * h1 - w2 * h2) < 1e-9 && h2 > h1) { h1 = h2; w1 = w2; } } } for (int x = 0; (1ll << x) <= w; x++) { w2 = (1 << x); h2 = ceil(w2 * .8 - 1e-9); if (h2 < floor(w2 * 1.25 + 1e-9) + 1e-9 && h2 < h + 1e-9) { h2 = min(h, floor(w2 * 1.25 + 1e-9)); if (w1 * h1 < w2 * h2) { w1 = w2; h1 = h2; } else if (abs(w1 * h1 - w2 * h2) < 1e-9 && h2 > h1) { h1 = h2; w1 = w2; } } } cout.precision(0); cout.flags(ios::fixed); cout << h1 << " " << w1 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int a, b; void out(int x, int y) { if (x <= b && y <= a && y > x) swap(y, x); cout << x << " " << y; } signed main() { cin >> a >> b; int x = 1, y = 1; long long ans1 = 0, ans2 = 0; for (;;) { if (y * 0.8 > a * 1.0 || y > b) break; if (y * 1.25 > a * 1.0) { ans1 = max(ans1, (long long)a * y); } else ans1 = max(ans1, (long long)(floor(1.25 * y + 0.0001) * y)); y *= 2; } y /= 2; for (;;) { if (x * 0.8 > b || x > a) break; if (x * 1.25 > b * 1.0) ans2 = max(ans2, (long long)b * x); else ans2 = max(ans2, (long long)floor(1.25 * x + 0.0001) * x); x *= 2; } x /= 2; if (ans1 > ans2) { out(ans1 / y, y); } else out(x, ans2 / x); return 0; }
#include <bits/stdc++.h> using namespace std; const int inf = INT_MAX; const double PI = 3.14159265; int dpx[4] = {0, 1, 0, -1}; int dpy[4] = {1, 0, -1, 0}; int main() { int x = 0, y = 0, ni; ios::sync_with_stdio(false); long long S = 0, a, b, i = 1; cin >> a >> b; while (i <= a) { ni = min(b, i * 5 / 4); if (i <= b * 5 / 4) { if (i * ni == S && x <= i) { x = i; y = ni; S = i * ni; } else if (i * ni > S) { x = i; y = ni; S = i * ni; } } i *= 2; } i = 1; while (i <= b) { ni = min(a, i * 5 / 4); if (i <= a * 5 / 4) { if (i * ni == S && x <= ni) { x = ni; y = i; S = i * ni; } else if (i * ni > S) { x = ni; y = i; S = i * ni; } } i *= 2; } cout << x << " " << y; }
#include <bits/stdc++.h> using namespace std; long long pow2[33]; long long cut(long long h, long long w) { bool ok = false; for (int i = (0); i < ((33)); ++i) if (pow2[i] == w) ok = true; if (4 * h > 5 * w) { if (!ok) { long long t = 1; while (2 * t <= h && 8 * t <= 5 * w) t *= 2; h = t; } else { h = 1.25 * w; while (4 * (h + 1) < 5 * w) h++; } } return h; } int main() { long long h, w; cin >> h >> w; pow2[0] = 1; for (int i = (1); i < (33); ++i) pow2[i] = pow2[i - 1] * 2; bool okh = false, okw = false; for (int i = (0); i < ((33)); ++i) if (pow2[i] == h) okh = true; for (int i = (0); i < ((33)); ++i) if (pow2[i] == w) okw = true; if (4 * h > 5 * w) { h = cut(h, w); cout << h << " " << w << endl; } else if (4 * w > 5 * h) { w = cut(w, h); cout << h << " " << w << endl; } else { if (!okh && !okw) { long long ww = 1; long long t = h; while (2 * ww <= w) ww *= 2; if (4 * h > 5 * ww) { t = cut(h, ww); } long long x = t * ww; long long hh = 1; long long s = w; while (2 * hh <= h) hh *= 2; if (4 * w > 5 * hh) { s = cut(w, hh); } long long y = hh * s; if (x >= y) { cout << t << " " << ww << endl; } else { cout << hh << " " << s << endl; } } else { cout << h << " " << w << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int h, w; cin >> h >> w; long long x, y, X = 1, Y = 1; for (x = 1; x <= h; x *= 2) if (ceil(x / 1.25) <= min(w, int(floor(x / 0.8)))) { y = min(w, int(floor(x / 0.8))); if (x * y > X * Y) { X = x; Y = y; } } for (y = 1; y <= w; y *= 2) if (ceil(0.8 * y) <= min(h, int(floor(1.25 * y)))) { x = min(h, int(floor(1.25 * y))); if (x * y > X * Y) { X = x; Y = y; } } for (x = 1; x <= h; x *= 2) if (ceil(x / 1.25) <= min(w, int(floor(x / 0.8)))) { y = min(w, int(floor(x / 0.8))); if (x * y == X * Y && x > X) { X = x; Y = y; } } for (y = 1; y <= w; y *= 2) if (ceil(0.8 * y) <= min(h, int(floor(1.25 * y)))) { x = min(h, int(floor(1.25 * y))); if (x * y == X * Y && x > X) { X = x; Y = y; } } cout << X << ' ' << Y << endl; return 0; }
#include <bits/stdc++.h> using namespace std; long long h, w; long long resh, resw, s; long long hh, ww; void pending(long long x, long long y) { if (x * y > s || x * y == s && x > resh) { s = x * y; resh = x, resw = y; } } int main() { long long i, j; long long lb, ub; while (cin >> h >> w) { resh = -1, resw = -1; s = -1; for (i = 1; i <= h; i *= 2) { lb = (i * 4 + 4) / 5; ub = i * 5 / 4; j = ub; if (w < ub) j = w; if (w < lb) break; pending(i, j); } for (i = 1; i <= w; i *= 2) { lb = (i * 4 + 4) / 5; ub = i * 5 / 4; j = ub; if (h < ub) j = h; if (h < lb) break; pending(j, i); } cout << resh << " " << resw << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; inline int read() { char ch = ' '; int f = 1, x = 0; while (!isdigit(ch)) { ch = getchar(); if (ch == '-') f *= -1; } while (isdigit(ch)) { x = (x << 3) + (x << 1) + ch - '0'; ch = getchar(); } return f * x; } double ans = 0; long long ansx = 0, ansy = 0; int main() { long long h = read(), w = read(); long long p1 = 1, p2 = 1; while (p1 <= h) p1 *= 2; p1 /= 2; while (p2 <= w) p2 *= 2; p2 /= 2; double l1 = p1 * 0.8, l2 = p2 * 0.8, r1 = p1 * 1.25, r2 = p2 * 1.25; if (w >= l1) { if (w < r1) { if (ans < p1 * w * 1.0) ans = p1 * w, ansx = p1, ansy = w; } else { if (ans < p1 * r1) ans = p1 * r1, ansx = p1, ansy = r1; } } if (h >= l2) { if (h < r2) { if (ans < p2 * h * 1.0) ans = p2 * h, ansx = h, ansy = p2; } else { if (ans < p2 * r2) ans = p2 * r2, ansx = r2, ansy = p2; } } if (ansx < ansy && ansx <= w && ansy <= h) swap(ansx, ansy); cout << ansx << " " << ansy; return 0; }
#include <bits/stdc++.h> using namespace std; long long ansh, answ, best; long long check(long long H, long long W) { long double rez = 1.0 * H / W; if (rez + 0.000000001 >= 0.8 && rez - 0.000000001 <= 1.25) return 1; if (rez + 0.000000001 < 0.8) return 0; return 2; } int main() { long long h, w, i, j; cin >> h >> w; for (i = 0; i <= 30; i++) { long long curh = (1 << i); if (curh > h) break; long long l = 1, r = w; if (check(curh, r) == 1) l = r; else { long long mid = 0; while (r - l > 1) { mid = (l + r) / 2; long long ind = check(curh, mid); if (ind == 1) l = mid; if (ind == 0) r = mid; if (ind == 2) l = mid; } } for (j = max(l - 10, 1LL); j <= min(l + 10, w); j++) { if (check(curh, j) == 1) { long long sq = j * curh; if (sq > best) { best = sq; ansh = curh; answ = j; } } } } for (i = 0; i <= 30; i++) { long long curw = (1 << i); if (curw > w) break; long long l = 1, r = h, bst = 0; if (check(r, curw) == 1) { l = r; bst = l; } else { while (r - l > 1) { long long mid = (l + r) / 2; long long ind = check(mid, curw); if (ind == 1) { l = mid; bst = mid; } if (ind == 0) l = mid; if (ind == 2) r = mid; } } for (j = max(bst - 10, 1LL); j <= min(bst + 10, h); j++) { if (check(j, curw) == 1) { long long sq = j * curw; if (sq >= best) { best = sq; ansh = j; answ = curw; } } } } cout << ansh << " " << answ; return 0; }
#include <bits/stdc++.h> using namespace std; long long int power(long long int a, long long int b) { if (b == 0) { return 1; } else if (b % 2 == 0) { return power(a * a, b / 2); } else { return a * power(a * a, (b - 1) / 2); } } pair<long long int, long long int> solve(long long int a, long long int b) { long long int c = log2(b); long long int d = power(2, c); if ((double)a / d < 0.8) { return make_pair(0, 0); } else if ((double)a / d < 1.25) { return make_pair(a, d); } else { a = 1.25 * d; return make_pair(a, d); } } int main() { long long int a, b; cin >> a >> b; pair<long long int, long long int> x, y; x = solve(a, b); y = solve(b, a); if (x.first * x.second >= y.first * y.second) { cout << x.first << " " << x.second; } else { cout << y.second << " " << y.first; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int x, y, r, l, curr, area, val1, val2, val; cin >> x >> y; long long int ans = -1; long long int st = 1; while (st <= x) { long long int curr = st; r = (st * 10) / 8; l = (st * 100) / 125 + min((long long int)1, (st * 100) % 125); if (r - l >= 0 && y >= l) { if (r < y) { area = curr * r; val = r; } else { area = curr * y; val = y; } if (ans <= area) { ans = area; val1 = curr; val2 = val; } } st = st * 2; } st = 1; while (st <= y) { long long int curr = st; r = (st * 125) / 100; l = (st * 8) / 10 + min((long long int)1, (st * 10) % 8); if (r - l >= 0 && x >= l) { if (r < x) { area = curr * r; val = r; } else { area = curr * x; val = x; } if (ans < area) { ans = area; val1 = val; val2 = curr; } else if (ans <= area && val >= val1) { ans = area; val1 = val; val2 = curr; } } st = st * 2; } cout << val1 << " " << val2 << "\n"; }
#include <bits/stdc++.h> int mas[400], arr[400], n; using namespace std; bool ok(long long h, long long w) { if (4 * w / 5 <= h && 5 * w / 4 >= h) return 1; return 0; } int main() { long long h1 = 1, h, w1 = 1, w, w_a = 0, h_a = 0, s = 0; cin >> h >> w; while (h1 <= h) { if (ok(h1, w)) { long long sum = h1 * w; if (sum > s) { s = sum; h_a = h1; w_a = w; } } long long cur = 5 * h1 / 4; if (cur <= w) if (ok(h1, cur)) { long long sum = h1 * cur; if (sum > s) { s = sum; h_a = h1; w_a = cur; } } h1 *= 2; } long long w_a1 = 0, h_a1 = 0, s1 = 0; while (w1 <= w) { if (ok(h, w1)) { long long sum = h * w1; if (sum > s1) { s1 = sum; h_a1 = h; w_a1 = w1; } } long long cur = 5 * w1 / 4; if (cur <= h) if (ok(cur, w1)) { long long sum = w1 * cur; if (sum > s1) { s1 = sum; h_a1 = cur; w_a1 = w1; } } w1 *= 2; } if (s > s1) cout << h_a << " " << w_a; else if (s1 > s) cout << h_a1 << " " << w_a1; else if (h_a > h_a1) cout << h_a << " " << w_a; else cout << h_a1 << " " << w_a1; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, m; scanf("%d%d", &n, &m); long long ax = 1, x = 2, s; long long ay = 1, y = 2; while (true) { if (x > n) break; y = x; if (x >= 4) y = x + (x >> 2); if (y > m) y = m; if (x * 4 > y * 5) break; ax = x; ay = y; s = x * y; x *= 2; } x = 2; y = 2; while (true) { if (x > m) break; y = x; if (x >= 4) y = x + (x >> 2); if (y > n) y = n; if (x * 4 > y * 5) break; if (s < x * y) { ax = x; ay = y; s = x * y; } x *= 2; } swap(ax, ay); if (ax > n) swap(ax, ay); cout << ax << " " << ay << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long h, w; cin >> h >> w; long long hb = 0, wb = 0; for (long long hn = 1; hn <= h; hn *= 2) { long long wmin = (hn * 8 - 1) / 10 + 1; long long wmax = hn * 10 / 8; if (wmin > w) continue; long long wn = min(wmax, w); if (hn * wn > hb * wb || (hn * wn == hb * wb && hn > hb)) { hb = hn; wb = wn; } } for (long long wn = 1; wn <= w; wn *= 2) { long long hmin = (wn * 8 - 1) / 10 + 1; long long hmax = wn * 10 / 8; if (hmin > h) continue; long long hn = min(hmax, h); if (hn * wn > hb * wb || (hn * wn == hb * wb && hn > hb)) { hb = hn; wb = wn; } } cout << hb << " " << wb << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int go(int x) { while (x - x & (-x)) { x -= x & (-x); } return x; } int main() { long long n, m, nn, mm, a = 1, b = 1; scanf("%I64d%I64d", &n, &m); nn = n, mm = m; while (a <= n && m > 0.8 * a) a *= 2; a /= 2; if (m > 1.25 * a) mm = 1.25 * a; while (b <= m && n > 0.8 * b) b *= 2; b /= 2; if (n > 1.25 * b) nn = 1.25 * b; if (a * mm > nn * b || (a * mm == nn * b && a > nn)) printf("%I64d %I64d\n", a, mm); else printf("%I64d %I64d\n", nn, b); return 0; }
#include <bits/stdc++.h> using namespace std; long long check(long long f) { long long h = 0; while (f > 1) { f /= 2; h++; } return h; } int main() { long long h, w, w1, h1, w2, h2, hh, ww, wt, ht; double eps; cin >> h >> w; hh = check(h); ww = check(w); ht = (1 << hh); wt = (1 << ww); h1 = h2 = h; w1 = w2 = w; eps = 1.0 * h / w; if (eps - 1.25 > 0.000000001) { while (eps - 1.25 > 0.0000000001) { h1 = (1 << hh); eps = 1.0 * h1 / w; hh--; } if (0.8 - eps > 0.0000000001) w1 = 5 * h1 / 4; if (wt == w) h2 = 5 * w / 4; else { ww--; w2 = (1 << ww); h2 = 5 * w2 / 4; } } else if (0.8 - eps > 0.0000000001) { while (0.8 - eps > 0.0000000001) { w1 = (1 << ww); eps = 1.0 * h1 / w1; ww--; } if (eps - 1.25 > 0.0000000001) h1 = 5 * w1 / 4; if (h == ht) w2 = 5 * h / 4; else { h2 = ht; w2 = 5 * h2 / 4; } } else if ((ht == h) || (wt == w)) { cout << h << " " << w; return 0; } else { h1 = ht; eps = 1.0 * h1 / w1; if (0.8 - eps > 0.000000001) w1 = 5 * h1 / 4; w2 = wt; eps = 1.0 * h2 / w2; if (eps - 1.25 > 0.0000000001) h2 = 5 * w2 / 4; } if ((h2 * w2 > h1 * w1) || ((h2 * w2 == w1 * h1) && (h2 > h1))) { h = h2; w = w2; } else { h = h1; w = w1; } cout << h << " " << w; return 0; }
#include <bits/stdc++.h> using namespace std; pair<long long int, long long int> solve(long long int a, long long int b) { long long int c = log2(b); long long int d = pow(2, c); if ((double)a / d < 0.8) { return make_pair(0, 0); } else if ((double)a / d < 1.25) { return make_pair(a, d); } else { a = 1.25 * d; return make_pair(a, d); } } int main() { long long int a, b; cin >> a >> b; pair<long long int, long long int> x, y; x = solve(a, b); y = solve(b, a); if (x.first * x.second >= y.first * y.second) { cout << x.first << " " << x.second; } else { cout << y.second << " " << y.first; } }
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:36777216") using namespace std; void solve(); int main() { ios::sync_with_stdio(0); solve(); return 0; } const double KEps = 1.0E-8; void solve() { long long h, w; cin >> h >> w; long long bh = 0, bw = 0, bs = 0; for (int pw = 0;; pw++) { long long h2 = 1LL << pw; if (h2 > h) break; long long w2 = 0; double c = (double)h2 / (double)w; if (c > 0.8 - KEps && c < 1.25 + KEps) { w2 = w; } else if (c < 0.8 + KEps) { w2 = (long long)((double)h2 / 0.8 + 0.5); } long long s2 = w2 * h2; if (bs < s2) { bh = h2; bw = w2; bs = s2; } else if (bs == s2 && h2 > bh) { bh = h2; bw = w2; bs = s2; } } for (int pw = 0;; pw++) { long long w2 = 1LL << pw; if (w2 > w) break; long long h2 = 0; double c = (double)h / (double)w2; if (c > 0.8 - KEps && c < 1.25 + KEps) { h2 = h; } else if (c > 1.25 - KEps) { h2 = (long long)((double)w2 * 1.25 + 0.5); } long long s2 = w2 * h2; if (bs < s2) { bh = h2; bw = w2; bs = s2; } else if (bs == s2 && h2 > bh) { bh = h2; bw = w2; bs = s2; } } cout << bh << ' ' << bw << '\n'; }
#include <bits/stdc++.h> using namespace std; int main() { long long h, w, x = 0, y = 0; cin >> h >> w; for (long long hh = 1; hh <= h; hh <<= 1) { long long ww = min(w, (hh * 5) >> 2); if (hh * 4 > 5 * ww) continue; if (ww * hh > x * y) x = hh, y = ww; else if (ww * hh == x * y && hh > x) x = hh, y = ww; } for (long long ww = 1; ww <= w; ww <<= 1) { long long hh = min(h, (ww >> 2) * 5); if (hh * 5 < 4 * ww) continue; if (ww * hh > x * y) x = hh, y = ww; else if (ww * hh == x * y && hh > x) x = hh, y = ww; } cout << x << ' ' << y; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; int h, w; cin >> h >> w; if ((h == 1 && w == 2) || (h == 2 && w == 1)) { cout << "1 1" << '\n'; return 0; } int t = 1; while (2 * t <= h && 2 * t <= w) t *= 2; int hx = min(h, (int)(1.25 * t)); int wx = min(w, (int)(1.25 * t)); if (hx >= wx) cout << hx << " " << t << '\n'; else cout << t << " " << wx << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; const long long OO = 1e8; const double EPS = (1e-7); int dcmp(double x, double y) { return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1; } int main() { ios::sync_with_stdio(false); long long h, w; cin >> h >> w; vector<int> vh; vector<int> vw; long long num = 1; while (num <= h) vh.push_back(num), num *= 2; num = 1; while (num <= w) vw.push_back(num), num *= 2; reverse(((vh).begin()), ((vh).end())); reverse(((vw).begin()), ((vw).end())); long long maxi = 0, maxh = 0, maxw; for (int i = 0; i < ((int)((vh).size())); ++i) { long long hh = vh[i]; double mwd = hh / 1.25 + EPS; if (mwd > w) continue; long long mw = hh / 0.8 + EPS; if (mw > w) mw = w; if (hh * mw > maxi || (hh * mw == maxi && hh > maxh)) maxi = hh * mw, maxh = hh, maxw = mw; } for (int i = 0; i < ((int)((vw).size())); ++i) { long long ww = vw[i]; double mhd = ww * 0.8 + EPS; if (mhd > h) continue; long long mh = ww * 1.25 + EPS; if (mh > h) mh = h; if (ww * mh > maxi || (ww * mh == maxi && mh > maxh)) maxi = ww * mh, maxh = mh, maxw = ww; } cout << maxh << " " << maxw << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef struct { int sum, suf, pre, max; } Node; int toint(const string &s) { stringstream ss; ss << s; int x; ss >> x; return x; } const int MAXN = 2e5 + 100; const int UP = 31; const long long int highest = 1e18; const double pi = acos(-1); const double Phi = 1.618033988749894; const int logn = 20; const double root5 = 2.236067977; const long long int inf64 = 1e16; const int ini = -1e9; long long int h, w, hh = 1, ww, ans = 0, rh, rw; int main() { cin >> h >> w; while (hh <= h) { ww = min(hh * 5 / 4, w); if (ww >= ceil(hh * 4.0 / 5) && hh * ww >= ans) ans = ww * hh, rh = hh, rw = ww; hh *= 2; } ww = 1; while (ww <= w) { hh = min(ww * 5 / 4, h); if (hh >= ceil(ww * 4.0 / 5) && ww * hh >= ans) { if (hh * ww == ans && hh > rh) rh = hh, rw = ww; if (ww * hh > ans) ans = ww * hh, rh = hh, rw = ww; } ww *= 2; } cout << rh << " " << rw << "\n"; return 0; }
#include <bits/stdc++.h> long long h, w; int main() { scanf("%lld%d", &h, &w); long long a = 1; while (a << 1 <= h && a << 1 <= w) a <<= 1; long long m = std::min(h, a * 5 / 4); long long n = std::min(w, a * 5 / 4); if (m >= n) printf("%lld %lld\n", m, a); else printf("%lld %lld\n", a, n); return 0; }
#include <bits/stdc++.h> using namespace std; long long W, H; long long bh = 0, bw = 0; int main() { cin >> H >> W; for (long long w = 1; w <= W; w *= 2) { long long h = min((5 * w) / 4, H); if ((4 * h <= 5 * w) && (4 * w <= 5 * h)) { if (w * h > bw * bh) { bw = w; bh = h; } else if (w * h == bw * bh) { if (h > bh) { bh = h; bw = w; } } } } for (long long h = 1; h <= H; h *= 2) { long long w = min(W, (5 * h) / 4); if ((4 * h <= 5 * w) && (4 * w <= 5 * h)) { if (w * h > bw * bh) { bw = w; bh = h; } else if (w * h == bw * bh) { if (h > bh) { bh = h; bw = w; } } } } cout << bh << " " << bw; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int64_t h, w, x, y; cin >> h >> w; x = y = 1; while (w >= x && w >= y) x *= 2, y *= 2; x /= 2; y /= 2; x = min(x, w); y = min(y, h); w = min(w, (int64_t)(y * 1.25)); h = min(h, (int64_t)(x * 1.25)); if (h * x >= y * w) cout << h << " " << x << endl; else cout << y << " " << w << endl; return 0; }
#include <bits/stdc++.h> using namespace std; long long read() { long long first = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { first = first * 10 + ch - '0'; ch = getchar(); } return first * f; } template <class T> inline void print(T first) { if (first < 0) putchar('-'), first = -first; register short a[20] = {}, sz = 0; while (first) a[sz++] = first % 10, first /= 10; if (sz == 0) putchar('0'); for (long long i = sz - 1; i >= 0; i--) putchar('0' + a[i]); } const long long inf = 2147483647; const long long llinf = 2e18; const long long mod = 998244353; const unsigned long long MAXMOD = (unsigned long long)mod * (mod - 1); long long w, h; long long first, second; long long p[111]; int main() { w = read(), h = read(); p[0] = 1; for (long long i = 1; i <= 30; i++) { p[i] = p[i - 1] * 2; } long long i = 30; for (; i >= 1; i--) { if (p[i] <= min(w, (long long)(h * 5 / 4))) break; } first = p[i]; second = min(h, (long long)(first * 5 / 4)); long long sz1 = first * second; long long xx = first, yy = second; i = 30; for (; i >= 1; i--) { if (p[i] <= min(h, (long long)(w * 5 / 4))) break; } second = p[i]; first = min(w, (long long)(second * 5 / 4)); long long sz2 = first * second; if (sz1 > sz2) { print(xx), putchar(' '), print(yy), putchar('\n'); } else if (sz2 > sz1) { print(first), putchar(' '), print(second), putchar('\n'); } else if (first > xx) { print(first), putchar(' '), print(second), putchar('\n'); } else print(xx), putchar(' '), print(yy), putchar('\n'); return 0; }
#include <bits/stdc++.h> using namespace std; int main(void) { long long h, w, nh, nw, maxs = 1, ansh = 1, answ = 1, kansh = 1, kansw = 1, kmaxs = 1; scanf("%I64d %I64d", &h, &w); nh = 1; nw = 1; while ((nh <= h) && (nh * 5 <= w * 4)) nh *= 2; if (nh > h) { ansh = nh / 2; answ = nh * 5; answ /= 8; maxs = ansh * answ; } else { nw = nh * 4; answ = max(w, nw / 5); if (answ > w) { nh /= 2; ansh = nh; answ = nh * 5; answ /= 4; maxs = ansh * answ; } else { ansh = nh; maxs = ansh * answ; } } nw = 1; nh = 1; while ((nw <= w) && (nw * 5 <= h * 4)) nw *= 2; if ((nw > w)) { nw /= 2; kansw = nw; kansh = nw * 5; kansh /= 4; kmaxs = kansh * kansw; } else { nh = nw * 4; kansh = max(h, nh / 5); if (kansh > h) { nw /= 2; kansw = nw; kansh = nw * 5; kansh /= 4; kmaxs = kansh * kansw; } else { kansw = nw; kmaxs = kansh * kansw; } } if (kmaxs > maxs) { ansh = kansh; answ = kansw; } if ((kmaxs == maxs) && (kansh > ansh)) { ansh = kansh; answ = kansw; } printf("%I64d %I64d", ansh, answ); return 0; }
#include <bits/stdc++.h> using namespace std; long long h, w, t, p = 1, a, b; int main() { register int i; scanf("%lld%lld", &h, &w); for (i = 0; i < 30; ++i, p <<= 1) { if (p <= h && 4 * p <= 5 * w) { t = min(w, 5 * p / 4); if (p * t > a * b || (p * t == a * b && a < p)) a = p, b = t; } if (p <= w && 4 * p <= 5 * h) { t = min(h, 5 * p / 4); if (p * t > a * b || (p * t == a * b && a < t)) a = t, b = p; } } printf("%lld %lld\n", a, b); }
#include <bits/stdc++.h> using namespace std; int main() { double h, w; cin >> h >> w; float rat = float(h) / float(w); if (rat > 1.25) { if ((ceil(log2(w)) == floor(log2(w))) ? 1 : 0) { h = floor(w * 1.25); } else { if (!(ceil(log2(h)) == floor(log2(h))) ? 1 : 0) h = pow(2, int(log2(h))); while ((h / w) > 1.25) h = h / 2; } } else if (rat < 0.8) { if ((ceil(log2(h)) == floor(log2(h))) ? 1 : 0) w = floor((h * 5) / 4); else { if (!(ceil(log2(w)) == floor(log2(w))) ? 1 : 0) w = pow(2, int(log2(w))); while (h / w < 0.8) w = w / 2; } } else if (!(ceil(log2(w)) == floor(log2(w))) ? 1 : 0 && !(ceil(log2(h)) == floor(log2(h))) ? 1 : 0) { long long int hd = h, wd = w; long long int x = pow(2, int(log2(w))); long long int y = (x * 5) / 4; y = min(hd, y); long long int a = pow(2, int(log2(h))); long long int b = (a * 5) / 4; b = min(wd, b); if (a * b > x * y) { h = a; w = b; } else if (a * b < x * y) { h = y; w = x; } else { if (a >= y) { h = a; w = b; } else { h = y; w = x; } } } cout << std::fixed << std::setprecision(0) << int(h) << " " << int(w); }
#include <bits/stdc++.h> using namespace std; const int INF = (1 << 30) - 1; const int DIRX[] = {-1, 0, 0, 1, -1, -1, 1, 1}, DIRY[] = {0, -1, 1, 0, -1, 1, -1, 1}; const double ERR = 1e-9, PI = (2 * acos(0.0)); template <class T> inline int size(T& t) { return (int)t.size(); } template <class T> inline T MIN(T a, T b) { return ((a < b) ? a : b); } template <class T> inline T MAX(T a, T b) { return ((b < a) ? a : b); } template <class T> inline void checkMIN(T& a, T b) { if (b < a) a = b; } template <class T> inline void checkMAX(T& a, T b) { if (a < b) a = b; } template <class T> inline T sqr(T x) { return (x * x); } int compareDouble(double x, double y) { double d = x - y; if (d > ERR) return 1; if (d < -ERR) return -1; return 0; } int compareDouble(double x, double y, double err) { double d = x - y; if (d > err) return 1; if (d < -err) return -1; return 0; } bool comp(pair<long long, long long> a, pair<long long, long long> b) { if (a.first * a.second != b.first * b.second) return (a.first * a.second > b.first * b.second); if (a.first != b.first) return (a.first > b.first); return false; } bool check(long long n, long long d) { if (4 * d > 5 * n) return false; if (4 * n > 5 * d) return false; return true; } int main() { long long x, y, a, b, aa, bb; cin >> x >> y; a = (long long)floor(pow(2.0, floor(log(double(x)) / log(2.0) + ERR)) + ERR); b = (long long)floor(pow(2.0, floor(log(double(y)) / log(2.0) + ERR)) + ERR); vector<pair<long long, long long> > v; if (b >= a) { bb = MIN(y, 5 * a / 4); v.push_back(make_pair(a, bb)); } if (b <= a && 4 * a <= 5 * b) { v.push_back(make_pair(a, b)); } if (a >= b) { aa = MIN(x, 5 * b / 4); v.push_back(make_pair(aa, b)); } if (a <= b && 4 * b <= 5 * a) { v.push_back(make_pair(a, b)); } sort((v).begin(), (v).end(), comp); cout << v[0].first << " " << v[0].second; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int l, w; cin >> l >> w; int k = 1; while (2 * k <= l && 2 * k <= w) { k = k * 2; } int bl = min(l, int(1.25 * k)); int bw = min(w, int(1.25 * k)); if (bl >= bw) { cout << bl << " " << k << endl; } else cout << k << " " << bw << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 50; const int maxm = 1e6 + 50; const double eps = 1e-10; const int max_index = 62; const int inf = 0x3f3f3f3f; const int MOD = 1e9 + 7; inline int read() { char c = getchar(); while (!isdigit(c)) c = getchar(); int x = 0; while (isdigit(c)) { x = x * 10 + c - '0'; c = getchar(); } return x; } int main() { long long n, m; while (cin >> n >> m) { long long ans = 0; long long area = 0; for (long long i = 1; i <= n; i <<= 1) { long long l = i * 4 / 5 + 1; long long r = i * 5 / 4; if (l > m) break; long long t = min(m, r); long long tmp = i * t; if (tmp > area || tmp == area && i > ans) { ans = i; area = tmp; } } for (long long i = 1; i <= m; i <<= 1) { long long l = i * 4 / 5 + 1; long long r = i * 5 / 4; if (l > n) break; long long t = min(n, r); long long tmp = i * t; if (tmp > area || tmp == area && ans < t) { ans = t; area = tmp; } } cout << ans << " " << area / ans << "\n"; } return 0; }
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; long long int c_p(long long int a, long long int n) { long long int ans = 1; a %= 1000000007; if (a == 0) { return a; } while (n > 0) { if (n & 1) { ans = (ans * a) % 1000000007; } n = n >> 1; a = (a * a) % 1000000007; } return ans; } void sieve_b(long long int* b, long long int max1) { for (long long int i = 3; i <= max1; i += 2) { b[i] = 1; } for (long long int i = 3; i <= max1; i += 2) { if (b[i] == 1) { for (long long int j = i * i; j <= max1; j += i) { b[j] = 0; } } } b[0] = b[1] = 0; b[2] = 1; } bool compare(const pair<long long int, string>& x, const pair<long long int, string>& y) { return (x.first > y.first); } long long int mod_add(long long int a, long long int b) { long long int ans; ans = ((a % 1000000007) + (b % 1000000007)) % 1000000007; return (ans % 1000000007); } long long int mod_m(long long int a, long long int b) { long long int ans; ans = ((a % 1000000007) * (b % 1000000007)) % 1000000007; return (ans % 1000000007); } long long int mod_s(long long int a, long long int b) { long long int ans; ans = ((a % 1000000007) - (b % 1000000007) + 1000000007) % 1000000007; return ans; } long long int fun(long long int x) { return c_p(x, 1000000007 - 2); } long long int count_d(long long int n) { long long int c = 0; for (long long int i = 1; i <= sqrt(n); i++) { if (n % i == 0) { if (n / i == i) { c++; } else { c += 2; } } } return c; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int t; t = 1; while (t--) { long long int h, w; cin >> h >> w; long long int ph = h, pw = w; long long int k = log2(w); w = (1ll << k); if (4 * h > 5 * w) { h = 5 * w / 4; } if (4 * w > 5 * h) { w = 5 * h / 4; } long long int o1 = log2(ph); ph = (1ll << o1); if (4 * ph > 5 * pw) { ph = 5 * pw / 4; } if (4 * pw > 5 * ph) { pw = 5 * ph / 4; } if (h * w < ph * pw) { cout << ph << " " << pw << '\n'; } else { cout << h << " " << w << '\n'; } } return 0; }
#include <bits/stdc++.h> using namespace std; long long pw[33]; int main() { pw[0] = 1; for (int i = 1; i < 33; ++i) pw[i] = 2 * pw[i - 1]; long long h, w; cin >> h >> w; long long mxS = 0, ah = 0, aw = 0; for (int i = 0; i < 31; ++i) { if (pw[i] > h) break; long long y = min((5 * pw[i]) / 4, w); if (4 * pw[i] <= 5 * y && y <= w) { if (pw[i] * y > mxS || pw[i] * y == mxS && pw[i] > ah) { ah = pw[i]; aw = y; mxS = ah * aw; } } } for (int i = 0; i < 31; ++i) { if (pw[i] > w) break; long long x = min((5 * pw[i]) / 4, h); if (4 * pw[i] <= 5 * x && x <= h) { if (pw[i] * x > mxS || pw[i] * x == mxS && x > ah) { ah = x; aw = pw[i]; mxS = ah * aw; } } } for (int i = 0; i < 31; ++i) { for (int j = 0; j < 31; ++j) { if (pw[i] <= h && pw[j] <= w) { if (pw[i] * 4 <= pw[j] * 5 && pw[i] * 5 >= pw[j] * 4) { if (pw[i] * pw[j] > mxS || pw[i] * pw[j] == mxS && pw[i] > ah) { ah = pw[i]; aw = pw[j]; mxS = ah * aw; } } } } } cout << ah << ' ' << aw << endl; return 0; }
#include <bits/stdc++.h> using namespace std; inline bool ok(double first, double second, double h, double w) { return first <= h && second <= w; } pair<double, double> best(double h, double w) { long long i = 1; pair<double, double> ans = {0, 0}; while (i <= h && ok(i, i * 0.8, h, w)) { double mx = min((long long)w, (long long)(i * 1.25)); ans = {i, mx}; i <<= 1; } return ans; } int main() { std::ios::sync_with_stdio(false); double h, w; cin >> h >> w; pair<double, double> p1 = best(h, w); pair<double, double> p2 = best(w, h); swap(p2.first, p2.second); pair<double, double> ans = p1; double s1 = p1.first * p1.second, s2 = p2.first * p2.second; if (s1 < s2 || (s1 == s2 && p1.first < p2.first)) ans = p2; long long first = ans.first, second = ans.second; cout << first << " " << second << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1e6; inline int getint() { int w = 0, q = 0; char c = getchar(); while ((c < '0' || c > '9') && c != '-') c = getchar(); if (c == '-') q = 1, c = getchar(); while (c >= '0' && c <= '9') w = w * 10 + c - '0', c = getchar(); return q ? -w : w; } long long h, w; int main() { cin >> h >> w; long long t = 1; long long a = 0, b = 0, p; for (int i = 0; i < 31; i++) { if (t <= h && 4 * t < 5 * w) { if (t <= h && 4 * t <= 5 * w) { p = min(w, 5 * t / 4); if ((a < t && p * t == a * b) || a * b < p * t) { a = t, b = p; } } if (t <= w && 4 * t <= 5 * h) { p = min(h, 5 * t / 4); if ((a < p && p * t == a * b) || a * b < p * t) { a = p, b = t; } } } t *= 2; } cout << a << " " << b << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int INF = (1 << 30) - 1; const int DIRX[] = {-1, 0, 0, 1, -1, -1, 1, 1}, DIRY[] = {0, -1, 1, 0, -1, 1, -1, 1}; const double ERR = 1e-9, PI = (2 * acos(0.0)); template <class T> inline int size(T& t) { return (int)t.size(); } template <class T> inline T MIN(T a, T b) { return ((a < b) ? a : b); } template <class T> inline T MAX(T a, T b) { return ((b < a) ? a : b); } template <class T> inline void checkMIN(T& a, T b) { if (b < a) a = b; } template <class T> inline void checkMAX(T& a, T b) { if (a < b) a = b; } bool comp(pair<long long, long long> a, pair<long long, long long> b) { if (a.first * a.second != b.first * b.second) return (a.first * a.second > b.first * b.second); if (a.first != b.first) return (a.first > b.first); return false; } int main() { long long x, y, a, b, aa, bb, i, j, xx, yy; while (cin >> x >> y) { vector<pair<long long, long long> > v; for (i = 1; i <= x; i *= 2) { if (y > i) { yy = MIN(y, (5 * i) / 4); v.push_back(make_pair(i, yy)); } if (y <= i && 4 * i <= 5 * y) { v.push_back(make_pair(i, y)); } } for (j = 1; j <= y; j *= 2) { if (x > j) { xx = MIN(x, (5 * j) / 4); v.push_back(make_pair(xx, j)); } if (x <= j && 4 * j <= 5 * x) { v.push_back(make_pair(x, j)); } } sort((v).begin(), (v).end(), comp); cout << v[0].first << " " << v[0].second << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9; const long long MOD = 998244353; const long long maxn = 1e5 + 1; long long RAND(long long n) { return abs((rand() << 15) + rand()) % n; } long long n = 1, h, w, s = -1, ans = -1, ans1; void dih(long long con1, long long con2, long long con3, long long num, long long l, long long r, bool tf) { while (r - l > 1) { long long mid = (l + r) / 2; if (mid * con2 > con3 * num) r = mid; else l = mid; } if (l * con2 >= con1 * num && l * con2 <= con3 * num) { if (!tf) ans1 = num; else ans1 = l; if (l * num == s) ans = max(ans, ans1); if (l * num > s) { ans = ans1; s = l * num; } } if (r * con2 >= con1 * num && r * con2 <= con3 * num) { if (!tf) ans1 = num; else ans1 = r; if (r * num == s) ans = max(ans, ans1); if (r * num > s) { ans = ans1; s = r * num; } } } void solveTask() { cin >> h >> w; while (n <= INF) { if (n <= w) dih(16, 20, 25, n, 1, h, 1); if (n <= h) dih(32, 40, 50, n, 1, w, 0); n *= 2; } cout << ans << ' ' << s / ans; } int main() { ios_base::sync_with_stdio(0); srand(time(0)); solveTask(); return 0; }
#include <bits/stdc++.h> using namespace std; void read_file(bool outToFile = true) {} int BS(int lo, int hi, int cond) { hi++; while (lo != hi - 1) { int md = (lo + hi) / 2; if (md <= 125LL * cond / 100) lo = md; else hi = md; } if (lo <= 125LL * cond / 100) return lo; else return -1; } void f(int h, int w, int &x, int &y) { int ansH = 1, ansW = 1; for (int i = 1; i <= h; i *= 2) { int j = BS(0, w, i); if (j == -1) continue; { if (!(8LL * i <= 10LL * j && 100LL * j <= 125LL * i)) continue; long long nw = 1LL * i * j, old = 1LL * ansH * ansW; if (nw > old || nw == old && ansH < i) ansH = i, ansW = j; } } long long nw = 1LL * ansH * ansW, old = 1LL * x * y; if (nw > old || nw == old && x < ansH) x = ansH, y = ansW; } void g(int h, int w, int &x, int &y) { int ansH = 1, ansW = 1; for (int j = 1; j <= w; j *= 2) { int i = BS(0, h, j); if (i == -1) continue; { if (!(8LL * j <= 10LL * i && 100LL * i <= 125LL * j)) continue; long long nw = 1LL * i * j, old = 1LL * ansH * ansW; if (nw > old || nw == old && ansH < i) ansH = i, ansW = j; } } long long nw = 1LL * ansH * ansW, old = 1LL * x * y; if (nw > old || nw == old && x < ansH) x = ansH, y = ansW; } int main() { read_file(); int h, w; while (scanf("%d %d\n", &h, &w) != EOF) { int ansH = 1, ansW = 1; f(h, w, ansH, ansW); g(h, w, ansH, ansW); printf("%d %d\n", ansH, ansW); } }
#include <bits/stdc++.h> using namespace std; long long H, W, h, w, i; pair<long long, long long> ans = make_pair(1, 1); int main() { cin >> H >> W; for (h = 1; h <= H; h <<= 1) { w = min(W, (5 * h) / 4); if (h * 4 <= 5 * w) ans = max(ans, make_pair(h * w, h)); } for (w = 1; w <= W; w <<= 1) { h = min(H, (5 * w) / 4); if (5 * h >= 4 * w) ans = max(ans, make_pair(h * w, h)); } cout << ans.second << " " << ans.first / ans.second; return 0; }
#include <bits/stdc++.h> using namespace std; long long res, mx, r1, r2; int main() { long long h, w, p, q; cin >> h >> w; p = 1; while (p <= h) { if (p > h) break; q = (long long)(p / 4.0 * 5.0); if (q > w) q = w; if ((long long)(q / 4.0 * 5.0) < p) break; if (p * q > mx) { mx = p * q; r1 = p; r2 = q; } p *= 2; } q = 1; while (q <= w) { if (q > w) break; p = (long long)(q / 4.0 * 5.0); if (p > h) p = h; if ((long long)(p / 4.0 * 5.0) < q) break; if (p * q > mx) { mx = p * q; r1 = p; r2 = q; } q *= 2; } if (r1 <= w && r2 <= h) { if (r1 < r2) { int temp = r1; r1 = r2; r2 = temp; } } cout << r1 << " " << r2 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int H, W; long double ans; long long w, h; void findw(long long h1) { long double l = 0.8; long double r = 100.0; long double m; while (r - l > 1e-10) { m = (l + r) / 2; if (floor(h1 / m) <= W) r = m; else l = m; } long double R; if (floor(h1 / r) <= W) R = r; else R = l; if (h1 * floor(h1 / R) > ans && floor(h1 / R) <= W && (h1 / floor(h1 / R) - 0.8 >= 1e-2 && h1 / floor(h1 / R) - 1.25 <= 1e-2)) { ans = h1 * floor(h1 / R); h = h1; w = floor(h1 / R); } if (h1 * ceil(h1 / R) > ans && ceil(h1 / R) <= W && (h1 / ceil(h1 / R) - 0.8 <= 1e-2 && h1 / ceil(h1 / R) - 1.25 <= 1e-2)) { ans = h1 * ceil(h1 / R); h = h1; w = ceil(h1 / R); } } void findh(long long w1) { long double l = 0.8; long double r = 10.0; long double m; while (r - l > 1e-10) { m = (l + r) / 2; if (floor(w1 * m) <= H) l = m; else r = m; } long double R; if (floor(w1 * r) <= H) R = r; else R = l; if (w1 * floor(w1 * R) > ans && floor(w1 * R) <= H && (floor(w1 * R) / w1 - 0.8 >= 1e-2 && floor(w1 * R) / w1 - 1.25 <= 1e-2)) { ans = w1 * floor(w1 * R); h = floor(w1 * R); w = w1; } if (w1 * ceil(w1 * R) > ans && ceil(w1 * R) <= H && (ceil(w1 * R) / w1 - 0.8 <= 1e-2 && ceil(w1 * R) / w1 - 1.25 <= 1e-2)) { ans = w1 * ceil(w1 * R); h = ceil(w1 * R); w = w1; } } int main() { cin >> H >> W; for (int i = 0; (1 << i) <= H; ++i) { long double a = (1 << i); findw(a); } for (int i = 0; (1 << i) <= W; ++i) { long double a = (1 << i); findh(a); } if (h <= W && w <= H && h < w) swap(h, w); cout << h << " " << w << endl; }
#include <bits/stdc++.h> using namespace std; int main() { double h, w; cin >> h >> w; float rat = float(h) / float(w); if (rat > 1.25) { if ((ceil(log2(w)) == floor(log2(w))) ? 1 : 0) { h = floor(w * 1.25); } else { if (!(ceil(log2(h)) == floor(log2(h))) ? 1 : 0) h = pow(2, int(log2(h))); while ((h / w) > 1.25) h = h / 2; } } else if (rat < 0.8) { if ((ceil(log2(h)) == floor(log2(h))) ? 1 : 0) w = floor((h * 5) / 4); else { if (!(ceil(log2(w)) == floor(log2(w))) ? 1 : 0) w = pow(2, int(log2(w))); while (h / w < 0.8) w = w / 2; } } else if (!(ceil(log2(w)) == floor(log2(w))) ? 1 : 0 && !(ceil(log2(h)) == floor(log2(h))) ? 1 : 0) { long long int hd = h, wd = w; long long int x = pow(2, int(log2(w))); long long int y = (x * 5) / 4; y = min(hd, y); long long int a = pow(2, int(log2(h))); long long int b = (a * 5) / 4; b = min(wd, b); if (a * b > x * y) { h = a; w = b; } else if (a * b < x * y) { h = y; w = x; } else { if (a >= y) { h = a; w = b; } else { h = y; w = x; } } } cout << std::fixed << std::setprecision(0) << int(h) << " " << int(w); }
#include <bits/stdc++.h> using namespace std; const double eps = 1e-7; const int oo = 1e+9; double h, w; pair<double, double> ans(1, 1); int main() { cin >> w >> h; double hh, ww; for (hh = 1; hh <= h; hh *= 2) { ww = min(int(1.25 * hh), int(w)); if (ww / hh >= 0.8 && ww * hh > ans.first * ans.second) ans.first = ww, ans.second = hh; } for (ww = 1; ww <= w; ww *= 2) { hh = min(int(1.25 * ww), int(h)); if (hh / ww >= 0.8 && ww * hh > ans.first * ans.second) ans.first = ww, ans.second = hh; } cout << int(ans.first) << ' ' << int(ans.second); return 0; }
#include <bits/stdc++.h> using namespace std; long long x, y, z, a, b, a1, b1, cnt; int main() { cin >> x >> y; for (long long i = 1; i <= x; i *= 2) { a1 = i; if (a1 <= x && 4 * a1 <= 5 * y) { b1 = 5 * a1 / 4; b1 = min(b1, y); if (a1 * b1 > z || (a1 * b1 == z && a1 > a)) { a = a1; b = b1; z = a * b; } } a1 = i; if (a1 <= y && 4 * a1 <= 5 * x) { b1 = 5 * a1 / 4; b1 = min(b1, x); if (a1 * b1 > z || (a1 * b1 == z && b1 > a)) { a = b1; b = a1; z = a * b; } } } cout << a << " " << b << endl; }
#include <bits/stdc++.h> using namespace std; const long long maxn = 1e6 + 10; const long long INF = 0x3f3f3f3f; const long long linf = 0x3f3f3f3f3f3f3f3f; const double PI = acos(-1.0); long long mod = 1e9 + 7; int32_t main() { long long h, w; cin >> h >> w; long long l = 0, r = 0; for (l = 0;; l++) { if ((1 << l) > h || (1 << l) > (5 * w) / 4) { l--; break; } } for (r = 0;; r++) { if ((1 << r) > w || (1 << r) > (5 * h) / 4) { r--; break; } } long long hh = 1 << l, ww = 1 << r; long long ans_h = min(h, 5 * ww / 4); long long ans_w = min(w, 5 * hh / 4); if (hh * ans_w > ww * ans_h) { cout << hh << " " << ans_w << endl; return 0; } else if (hh * ans_w < ww * ans_h) { cout << ans_h << " " << ww << endl; } else cout << max(hh, ans_h) << " " << min(ww, ans_w) << endl; }
#include <bits/stdc++.h> using namespace std; int h, w; long long best_h, best_w; long double ep = 0.0000000001; int main() { cin >> h >> w; long long l, r, re; int i; for (i = 1; i <= h; i *= 2) { l = 0; r = w + 1; while (r - l > 1) { re = ((l + r) >> 1); if ((long double)i / (long double)re < 0.8 - ep) r = re; else l = re; } if ((long double)i / (long double)l < 1.25 + ep && i * l >= best_h * best_w) { best_h = i; best_w = l; } } for (i = 1; i <= w; i *= 2) { l = 0; r = h + 1; while (r - l > 1) { re = ((l + r) >> 1); if ((long double)re / (long double)i > 1.25 + ep) r = re; else l = re; } if ((long double)l / (long double)i > 0.8 - ep) { if (i * l > best_h * best_w) { best_h = l; best_w = i; } else if (i * l == best_h * best_w && l > best_h) { best_h = l; best_w = i; } } } cout << best_h << " " << best_w << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int INF = (1 << 30) - 1; const int DIRX[] = {-1, 0, 0, 1, -1, -1, 1, 1}, DIRY[] = {0, -1, 1, 0, -1, 1, -1, 1}; const double ERR = 1e-9, PI = (2 * acos(0.0)); template <class T> inline int size(T& t) { return (int)t.size(); } template <class T> inline T MIN(T a, T b) { return ((a < b) ? a : b); } template <class T> inline T MAX(T a, T b) { return ((b < a) ? a : b); } template <class T> inline void checkMIN(T& a, T b) { if (b < a) a = b; } template <class T> inline void checkMAX(T& a, T b) { if (a < b) a = b; } bool comp(pair<long long, long long> a, pair<long long, long long> b) { if (a.first * a.second != b.first * b.second) return (a.first * a.second > b.first * b.second); if (a.first != b.first) return (a.first > b.first); return false; } int main() { long long x, y, a, b, aa, bb, i, j, xx, yy; cin >> x >> y; vector<pair<long long, long long> > v; for (i = 1; i <= x; i *= 2) { if (y > i) { yy = MIN(y, (5 * i) / 4); v.push_back(make_pair(i, yy)); } if (y <= i && 4 * i <= 5 * y) { v.push_back(make_pair(i, y)); } } for (j = 1; j <= y; j *= 2) { if (x > j) { xx = MIN(x, (5 * j) / 4); v.push_back(make_pair(xx, j)); } if (x <= j && 4 * j <= 5 * x) { v.push_back(make_pair(x, j)); } } sort((v).begin(), (v).end(), comp); cout << v[0].first << " " << v[0].second; return 0; }
#include <bits/stdc++.h> int main() { long long h, w; std::cin >> h >> w; long long H = -1, W; for (long long i = 1; i <= h; i *= 2) { long long j = std::min((5 * i) / 4, w); if (5 * i < 4 * j || 4 * i > 5 * j) continue; if (H == -1) { H = i; W = j; } else { if (H * W < i * j || H * W == i * j && H < i) { H = i; W = j; } } } for (long long j = 1; j <= w; j *= 2) { long long i = std::min((5 * j) / 4, h); if (5 * i < 4 * j || 4 * i > 5 * j) continue; if (H == -1) { H = i; W = j; } else { if (H * W < i * j || H * W == i * j && H < i) { H = i; W = j; } } } std::cout << H << " " << W << "\n"; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); long long int h, w; cin >> h >> w; long long int ansh = 0, answ = 0; long long int temp = 1; for (long long int i = 0; i <= 30; i++) { if (temp <= h && 4 * temp <= 5 * w) { long long int t = min(w, 5 * temp / 4); if ((temp * t > ansh * answ) || (temp * t == ansh * answ && temp > ansh)) { ansh = temp; answ = t; } } if (temp <= w && 5 * h >= 4 * temp) { long long int t = min(h, 5 * temp / 4); if ((temp * t > ansh * answ) || (temp * t == ansh * answ && t > ansh)) { ansh = t; answ = temp; } } temp *= 2; } cout << ansh << " " << answ << endl; }
#include <bits/stdc++.h> using namespace std; template <class T> typename T::value_type arr_sum(const T& v, int n) { typename T::value_type sum = 0; for (int i = (0); i < (n); ++i) sum += v[i]; return sum; } struct Sync_stdio { Sync_stdio() { cin.tie(NULL); ios_base::sync_with_stdio(false); } } _sync_stdio; int main() { long long h, w; cin >> h >> w; long long maxh = 0, maxw = 0; for (int i = 1; i <= h; i <<= 1) { long long tw = min(w, (long long)i * 5 / 4); if (tw * 5 < i * 4) { continue; } if (tw * i > maxh * maxw || (tw * i == maxh * maxw && i > maxh)) { maxh = i; maxw = tw; } } for (int i = 1; i <= w; i <<= 1) { long long th = min(h, (long long)i * 5 / 4); if (th * 5 < i * 4) { continue; } if (th * i > maxh * maxw || (th * i == maxh * maxw && th > maxh)) { maxh = th; maxw = i; } } cout << maxh << " " << maxw << "\n"; }
#include <bits/stdc++.h> using namespace std; bool isprime(long long int n) { if (n < 2) return false; for (long long int i = 2; i <= sqrt(n); i++) if (n % i == 0) return false; return true; } long long gcd(long long int a, long long int b) { if (a == 0 || b == 0) return a + b; else return gcd(b, a % b); } void MAIN(); int main() { ios_base::sync_with_stdio(false); cin.tie(0); MAIN(); return 0; } long long int ansh, answ; void update(long long int h, long long int w) { if (h * w > ansh * answ || h * w == ansh * answ && h > ansh) { ansh = h; answ = w; } } void MAIN() { long long int h, w; cin >> h >> w; for (int i = 0; (1ll << i) <= max(h, w); ++i) { long long int e = 1ll << i, f; if (h >= e) { if (4 * e > 5 * w) continue; if (5 * e < 4 * w) { f = 5 * e / 4; } else f = w; update(e, f); } if (w >= e) { if (5 * h < 4 * e) continue; if (4 * h > 5 * e) f = 5 * e / 4; else f = h; } update(f, e); } cout << ansh << ' ' << answ << endl; }
#include <bits/stdc++.h> using namespace std; long long h, w, p = 1ll, a, b, temp, times = 30ll; int main() { scanf("%lld%lld", &h, &w); while (times--) { if (p <= h && (p << 2ll) <= 5ll * w) { temp = min(w, 5ll * p >> 2ll); if (p * temp > a * b || (p * temp == a * b && a < p)) { a = p; b = temp; } } if (p <= w && (p >> 2ll) <= 5ll * h) { temp = min(h, 5ll * p >> 2ll); if (p * temp > a * b || (p * temp == a * b && a < temp)) { a = temp; b = p; } } p <<= 1ll; } printf("%lld %lld\n", a, b); return 0; }
#include <bits/stdc++.h> using namespace std; long long h, w; long long ax, ay, area; int main() { cin >> h >> w; long long x, y; for (x = 1; x <= h; x *= 2) { y = min(x * 5 / 4, w); if (y * 5 < x * 4) continue; if (x * y > area || (x * y == area && x > ax)) ax = x, ay = y, area = x * y; } for (y = 1; y <= w; y *= 2) { x = min(y * 5 / 4, h); if (x * 5 < y * 4) continue; if (x * y > area || (x * y == area && x > ax)) ax = x, ay = y, area = x * y; } cout << ax << ' ' << ay << endl; { int _; cin >> _; } }
#include <bits/stdc++.h> using namespace std; long long lowest_2(long long num) { long long res = 1; while (res <= num) res *= 2; res /= 2; return res; } void print(long long a1, long long a2) { cout << a1 << " " << a2 << endl; } int main() { long long h, w; cin >> h >> w; long long new_h, new_w; new_h = lowest_2(h); new_w = lowest_2(w); long long res1_h, res1_w, res2_h, res2_w; res1_h = new_h; res1_w = (long long)floor(res1_h / 0.8); res2_w = new_w; res2_h = (long long)floor(1.25 * res2_w); if (res1_w <= w && res2_h <= h) { if (res1_h * res1_w > res2_h * res2_w) print(res1_h, res1_w); else if (res1_h * res1_w < res2_h * res2_w) print(res2_h, res2_w); else { if (res1_h > res2_h) print(res1_h, res1_w); else print(res2_h, res2_w); } } else if (res1_w <= w) print(res1_h, res1_w); else if (res2_h <= h) print(res2_h, res2_w); else { res1_w = w; res2_h = h; if (res1_h * res1_w > res2_h * res2_w) print(res1_h, res1_w); else if (res1_h * res1_w < res2_h * res2_w) print(res2_h, res2_w); else { if (res1_h > res2_h) print(res1_h, res1_w); else print(res2_h, res2_w); } } }
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9; int main() { long long H, W; cin >> H >> W; pair<long long, pair<long long, long long> > res = make_pair(-INF, make_pair(-INF, -INF)); for (long long w = 1; w <= W; w <<= 1) { long long h = min(H, 125 * w / 100); if (h > H || 100 * h < 80 * w) continue; res = max(res, make_pair(h * w, make_pair(h, w))); } for (long long h = 1; h <= H; h <<= 1) { long long w = min(W, 100 * h / 80); if (w > W || 100 * h > 125 * w) continue; res = max(res, make_pair(h * w, make_pair(h, w))); } cout << res.second.first << ' ' << res.second.second << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); double h, w; cin >> h >> w; int ans1, ans2, mx = 0; long long int i = 1; while (i * 2 <= h && i * 2 <= w) { i *= 2; } ans1 = min((long long int)h, (long long int)(1.25 * i)); ans2 = min((long long int)w, (long long int)(1.25 * i)); if (ans1 >= ans2) cout << ans1 << " " << i; else cout << i << " " << ans2; return 0; }
#include <bits/stdc++.h> using namespace std; struct item { int x, y; long long s; item() {} item(int _x, int _y) { x = _x; y = _y; s = (long long)x * y; } bool operator<(const item &a) { if (s != a.s) return s < a.s; return y < a.y; } }; int main() { int a, b; cin >> a >> b; double eps = 1e-7; double y = -1; double x; double z, zz; item ans(0, 0), t; double ko; double dx[] = {0.8, 1.25, 1}; while (y <= a) { if (y == -1) y = 1; else y *= 2; x = y / 0.8; if (x > b + eps) x = b; if (y > a + eps) continue; x = floor(x); ko = y / x; if (ko > 1.25 + eps || ko < 0.8 - eps) continue; t = item(x, y); if (ans < t) ans = t; } x = -1; while (x <= b) { if (x == -1) x = 1; else x *= 2; y = x * 1.25; if (y > a + eps) y = a; if (x > b + eps) continue; x = floor(x); ko = y / x; if (ko > 1.25 + eps || ko < 0.8 - eps) continue; if (y > a + eps || y < 0) continue; t = item(x, y); if (ans < t) ans = t; } cout << ans.y << " " << ans.x; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long h, w, x = 0, y = 0; cin >> h >> w; for (long long hh = 1; hh <= h; hh <<= 1) { long long ww = min(w, (long long)ceil((hh << 2) / 5.0)); if (hh * 4 > 5 * ww) continue; if (ww * hh > x * y) x = hh, y = ww; else if (ww * hh == x * y && hh > x) x = hh, y = ww; ww = min(w, (hh >> 2) * 5); if (hh * 5 < 4 * ww) continue; if (ww * hh > x * y) x = hh, y = ww; else if (ww * hh == x * y && hh > x) x = hh, y = ww; } for (long long ww = 1; ww <= w; ww <<= 1) { long long hh = min(h, (ww >> 2) * 5); if (hh * 5 < 4 * ww) continue; if (ww * hh > x * y) x = hh, y = ww; else if (ww * hh == x * y && hh > x) x = hh, y = ww; hh = min(h, (long long)ceil((hh << 2) / 5.0)); if (hh * 4 > 5 * ww) continue; if (ww * hh > x * y) x = hh, y = ww; else if (ww * hh == x * y && hh > x) x = hh, y = ww; } cout << x << ' ' << y; return 0; }
#include <bits/stdc++.h> using namespace std; long long hm = 0, wm = 0; void compare(long long h, long long w) { if ((h * w > hm * wm) || (h * w == hm * wm && h > hm)) { hm = h; wm = w; } return; } void func(long long h, long long w, bool b) { long long hnew = 1; while (hnew <= h) { double r = w * 1.0 / hnew; if (r >= 1.25) { if (b) compare(hnew, hnew * 1.25); else compare(hnew * 1.25, hnew); } else if (r >= 0.8) { if (b) compare(hnew, w); else compare(w, hnew); } hnew *= 2; } } int main() { long long h, w; cin >> h >> w; func(h, w, true); func(w, h, false); cout << hm << " " << wm << endl; }
#include <bits/stdc++.h> using namespace std; void calc(uint64_t h, uint64_t w, uint64_t& hmax, uint64_t& wmax, uint64_t& areamax) { uint64_t temp = h * w; if (temp > areamax) { areamax = temp; hmax = h; wmax = w; } else if (temp == areamax) { if (h > hmax) { hmax = h; wmax = w; } } } int main() { uint64_t hi, wi; cin >> hi >> wi; vector<int> hv, wv; uint64_t val = 1; while (val <= hi) { hv.push_back(val); val *= 2; } val = 1; while (val <= wi) { wv.push_back(val); val *= 2; } uint64_t areamax = 0, hmax = 0, wmax; for (const auto& h : hv) { uint64_t w1 = ceil(((double)(h)*4) / 5); uint64_t w2 = floor(((double)(h)*5) / 4); uint64_t w = 0; if (wi >= w1) { w = min(wi, w2); calc(h, w, hmax, wmax, areamax); } } for (const auto& w : wv) { uint64_t h1 = ceil(((double)(w)*4) / 5); uint64_t h2 = floor(((double)(w)*5) / 4); uint64_t h = 0; if (hi >= h1) { h = min(hi, h2); calc(h, w, hmax, wmax, areamax); } } cout << hmax << " " << wmax << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long h, w; cin >> h >> w; long long area = 0, hh = 0, ww = 0; for (long long i = 1; i <= h; i <<= 1) { for (int v = 16; v <= 25; v += 25 - 16) { long long j = min(w, 20 * i / v); if (16 * j <= 20 * i && 20 * i <= 25 * j) { if (i * j > area) { area = i * j; hh = i; ww = j; } } } } for (long long j = 1; j <= w; j <<= 1) { for (int v = 16; v <= 25; v += 25 - 16) { long long i = min(h, v * j / 20); if (16 * j <= 20 * i && 20 * i <= 25 * j) { if (i * j > area || (i * j == area && i > hh)) { area = i * j; hh = i; ww = j; } } } } cout << hh << " " << ww << endl; return 0; }
#include <bits/stdc++.h> long long h, w; long long ansh, answ; void judge(long long x, long long y) { if (x * y < ansh * answ) { return; } if (x * y > ansh * answ) { ansh = x; answ = y; return; } if (x * y == ansh * answ && x > ansh) { ansh = x; answ = y; } } int main() { while (scanf("%d%d", &h, &w) != EOF) { long long i, j; for (i = 1; i <= h; i *= 2) { long long hh = i; long long ww = (i * 5) / 4; if (ww > w) { ww = w; } if (((ww * 4 + 4) / 5) <= hh && ((hh * 4 + 4) / 5) <= ww) { judge(hh, ww); } } for (j = 1; j <= w; j *= 2) { long long ww = j; long long hh = (j * 5) / 4; if (hh > h) { hh = h; } if (((ww * 4 + 4) / 5) <= hh && ((hh * 4 + 4) / 5) <= ww) { judge(hh, ww); } } printf("%lld %lld\n", ansh, answ); } return 0; }
#include <bits/stdc++.h> using namespace std; long long int mul(long long int a, long long int b) { return ((a % int(1e9 + 7)) * (b % int(1e9 + 7))) % int(1e9 + 7); } long long int add(long long int a, long long int b) { return ((a % int(1e9 + 7)) + (b % int(1e9 + 7))) % int(1e9 + 7); } long long int sub(long long int a, long long int b) { long long int ans = ((a % int(1e9 + 7)) - (b % int(1e9 + 7))) % int(1e9 + 7); ans %= int(1e9 + 7); ans = (ans + int(1e9 + 7)) % int(1e9 + 7); return ans; } long long int mpow(long long int a, long long int b) { long long int ans = 1; long long int po = a; while (b != 0) { if (b % 2) { ans = ((ans % int(1e9 + 7)) * (po % int(1e9 + 7))) % int(1e9 + 7); } po = ((po % int(1e9 + 7)) * (po % int(1e9 + 7))) % int(1e9 + 7); b /= 2; } return ans; } void solve() { long long int h, w; cin >> h >> w; long long int ans = 0, ffh, ffw; for (int i = 0; i < 2; i++) { if (!i) swap(w, h); if (!i) swap(ffw, ffh); long long int fh = 1LL << (long long int)floor(log2(h) + 1e-5); while (w < fh / 1.25) { fh /= 2; } long long int fw = min(w, (long long int)(fh / .8 + 1e-5)); if (ans < fh * fw) { ans = fh * fw; ffh = fh; ffw = fw; } else if (ans == fh * fw) { if (i == 1 and fh > ffh) { ffh = fh; ffw = fw; } else if (i == 0 and fw > ffw) { ffh = fh; ffw = fw; } } if (!i) { swap(w, h); swap(ffw, ffh); } } cout << ffh << ' ' << ffw << '\n'; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int t; solve(); }
#include <bits/stdc++.h> using namespace std; int main() { long long int x, y, h, w, ansx = -1, ansy = -1, area = -1; cin >> h >> w; for (x = 1; x <= h; x = x * 2) { y = min(x * 5 / 4, w); if (y * 5 < x * 4) continue; if (x * y > area || (x * y == area && x > ansx)) { ansx = x; ansy = y; area = x * y; } } for (y = 1; y <= w; y = y * 2) { x = min(y * 5 / 4, h); if (x * 5 < y * 4) continue; if (x * y > area || (x * y == area && x > ansx)) { ansx = x; ansy = y; area = x * y; } } cout << ansx << " " << ansy; return 0; }
#include <bits/stdc++.h> using namespace std; long long hmax = 0, wmax = 0; void case1(long long h, long long w) { long long hnew = 1; while (hnew <= h) hnew *= 2; hnew /= 2; double w1 = hnew * 0.8, w2 = hnew * 1.25; if (w < w1) return; if (w > w2) w = w2; if (hmax * wmax < hnew * w) { hmax = hnew; wmax = w; } else if (hmax * wmax == hnew * w && hmax < hnew) { hmax = hnew; wmax = w; } return; } void case2(long long h, long long w) { long long wnew = 1; while (wnew <= w) wnew *= 2; wnew /= 2; double h1 = wnew * 0.8, h2 = wnew * 1.25; if (h < h1) return; if (h > h2) h = h2; if (hmax * wmax < wnew * h) { hmax = h; wmax = wnew; } else if (hmax * wmax == wnew * h && hmax < h) { hmax = h; wmax = wnew; } return; } void case3(long long h, long long w) { double w1 = h * 0.8, w2 = h * 1.25; long long wnew = 1; while (wnew <= w2) wnew *= 2; wnew /= 2; if (wnew < w1 || wnew > w) return; if (hmax * wmax < wnew * h) { hmax = h; wmax = wnew; } else if (hmax * wmax == wnew * h && hmax < h) { hmax = h; wmax = wnew; } return; } void case4(long long h, long long w) { double h1 = w * 0.8, h2 = w * 1.25; long long hnew = 1; while (hnew <= h2) hnew *= 2; hnew /= 2; if (hnew < h1 || hnew > h) return; if (hmax * wmax < w * hnew) { hmax = hnew; wmax = w; } else if (hmax * wmax == w * hnew && hmax < hnew) { hmax = hnew; wmax = w; } return; } int main() { long long h, w; cin >> h >> w; case1(h, w); case2(h, w); cout << hmax << " " << wmax << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long int l, w; cin >> l >> w; int k = 1; while (2 * k <= l && 2 * k <= w) k = k * 2; long long int ansl = min(l, (long long int)(1.25 * k)); long long int answ = min(w, (long long int)(1.25 * k)); if (ansl >= answ) cout << ansl << " " << k; else cout << k << " " << answ; return 0; }
#include <bits/stdc++.h> long long h, w, t, p = 1, a, b; int main(void) { register int i; scanf("%lld%lld", &h, &w); for (i = 0; i < 30; ++i, p <<= 1) { if (p <= h && 4 * p <= 5 * w) { t = ((w) < (5 * p / 4) ? (w) : (5 * p / 4)); if (p * t > a * b || (p * t == a * b && a < p)) a = p, b = t; } if (p <= w && 4 * p <= 5 * h) { t = ((h) < (5 * p / 4) ? (h) : (5 * p / 4)); if (p * t > a * b || (p * t == a * b && a < t)) a = t, b = p; } } printf("%lld %lld\n", a, b); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; template <class t> using V = vector<t>; ll area; int resh, resw; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int h, w; cin >> h >> w; int tmph = 1; while (tmph <= h) { ll g = (ll)floor((long double)tmph * 1.25); ll d = (ll)ceil((long double)tmph * 0.8); g = min((ll)w, g); if (g >= d) if ((area < (ll)tmph * g) or (area == (ll)tmph * g and resh < tmph)) { area = (ll)tmph * g; resh = tmph; resw = g; } tmph *= 2; } int tmpw = 1; while (tmpw <= w) { ll g = (ll)floor((long double)tmpw * 1.25); ll d = (ll)ceil((long double)tmpw * 0.8); g = min((ll)h, g); if (g >= d) if ((area < (ll)tmpw * g) or (area == (ll)tmpw * g and resh < g)) { area = (ll)tmpw * g; resh = g; resw = tmpw; } tmpw *= 2; } cout << resh << ' ' << resw << '\n'; }
#include <bits/stdc++.h> using namespace std; pair<long long, int> find(int h, int w) { pair<long long, int> res = make_pair(-1, -1); for (int i = 1; i <= h; i *= 2) { if (5 * (long long)w < 4 * (long long)i) break; int len = (int)(1.25 * i); len = min(len, w); pair<long long, int> t = make_pair((long long)i * len, i); res = max(res, t); } for (int i = 1; i <= w; i *= 2) { if (5 * (long long)h < 4 * (long long)i) break; int len = (int)(1.25 * i); len = min(len, h); pair<long long, int> t = make_pair((long long)i * len, len); res = max(res, t); } return res; } int main() { int h, w; cin >> h >> w; pair<long long, int> ans = find(h, w); cout << ans.second << " " << ans.first / ans.second; return 0; }