CF2027A-Rectangle Arrangement
题目大意
一个无限大的平面上,给你 \(n\) 个矩形,你可以在平面上任意放置矩形,要求最小矩形覆盖周长。
题解
考虑贪心做法,将所有矩形左下角都放在 \((0,0)\) 上。记录最长的 \(x\) 坐标和 \(y\) 坐标。此时面积就是 \(2*(l+r)\) 。
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ls(p) (p << 1)
#define rs(p) (ls(p) ^ 1)
typedef pair<int, int> pii;
const int INF = 1e16;
const int N = 3e5 + 5;inline int read();
inline void solve()
{int n = read(), l = 0, r = 0;for (int i = 1; i <= n; ++i){int x = read(), y = read();l = max(l, x);r = max(r, y);}printf("%lld\n", 2 * (l + r));
}signed main()
{int T = read();while (T--)solve();return 0;
}inline int read()
{int x = 0, f = 1;char ch = getchar();while (ch < '0' || ch > '9'){if (ch == '-')f = -1;ch = getchar();}while (ch >= '0' && ch <= '9'){x = (x << 1) + (x << 3) + (ch ^ 48);ch = getchar();}return x * f;
}