[贪心] Unija
题目
题目描述
有
样例输出
时空限制
题解
一道简单的贪心
题目是说在平面内,但我们只需要做出第一象限中的,然后将答案乘
考虑如何贪心,我们按横坐标从小到大排序,那么只看
再考虑如何得矩形的宽,因为在
代码
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
template <typename T>
T Fabs(T x) {return x < 0 ? -x : x;}
template <typename T>
T Max(T x, T y) {return x > y ? x : y;}
#define LL long long
const int N = 1000005;
LL x, y, ans;
int n, idx;
struct node {
LL x, y;
bool operator < (const node &rhs) const {
return x < rhs.x;
}
};
node a[N];
int main() {
freopen("unija.in", "r", stdin);
freopen("unija.out", "w", stdout);
scanf("%d", &n);
for(int i = 1; i <= n; i ++) {
scanf("%lld%lld", &x, &y);
a[i].x = x / 2;
a[i].y = y / 2;
}
sort(a + 1, a + 1 + n);
for(int i = n; i >= 1; i --)
a[i].y = Max(a[i].y, a[i + 1].y);
for(int i = 1; i <= n; i ++)
ans += (a[i]. x - a[i - 1].x) * a[i].y;
printf("%lld\n", ans * 4);
return 0;
}