Symmetrical Painting
题意:给你矩阵的L和R矩阵为(i-1,L)和(i,R)组成给你一条线求在先两侧对称的面积。
分析:我们可以想像一下,在矩阵的两侧而后所得最大面积为矩阵的中心和两侧,而超过一个矩阵的中心后他的面积就开始减少,在未到达中心前这个矩阵的面积是增加的,分别枚举由此我们可以得到结果。
#include<iostream>
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
const int maxn = 3000000;
ll n, cnt, a, b;
struct nod{
ll a, b;
}P[maxn];
bool cmp(nod m, nod n)
{
return m.a < n.a;
}
int main()
{
scanf("%lld", &n);
while(n--)
{
scanf("%lld%lld", &a, &b);
a <<= 1, b <<= 1; /// 两倍注意
P[++cnt].a = a, P[cnt].b = 1;
P[++cnt].a = (a + b) >> 1, P[cnt].b = -2; /// 过了中心其他加这个矩形减
P[++cnt].a = b, P[cnt].b = 1;
}
sort(P + 1, P + cnt + 1, cmp);
ll ans = 0, tmp = 0, pre = 0, res = 0;
for(int i = 1; i < cnt; i++)
{
pre += P[i].b;
tmp = P[i + 1].a - P[i].a;
res += tmp * pre;
ans = max(ans, res);
}
printf("%lld\n", ans);
return 0;
}