【BZOJ 4581】【Usaco2016 Open】Field Reduction

http://www.lydsy.com/JudgeOnline/problem.php?id=4581
考虑\(O(n^3)\)暴力。
实际上枚举最靠边的三个点就可以了,最多有12个点。
还是暴力= =
847398-20161116144216795-1869884798.jpg

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;

const int N = 50003;
int x[N], y[N], id[N], n, minx, maxx, miny, maxy, ansminx, ansmaxx, ansminy, ansmaxy, a[N], tot = 0;

bool cmpx(int X, int Y) {return x[X] < x[Y];}
bool cmpy(int X, int Y) {return y[X] < y[Y];}

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i)
        scanf("%d%d", x + i, y + i);
    for (int i = 1; i <= n; ++i) id[i] = i;
    minx = miny = 0x7fffffff; maxx = maxy = -0x7fffffff;
    
    stable_sort(id + 1, id + n + 1, cmpx);
    minx = min(minx, x[id[4]]);
    maxx = max(maxx, x[id[n - 3]]);
    for (int i = 0; i < 3; ++i) {
        a[++tot] = id[1 + i];
        a[++tot] = id[n - i];
    }
    
    stable_sort(id + 1, id + n + 1, cmpy);
    miny = min(miny, y[id[4]]);
    maxy = max(maxy, y[id[n - 3]]);
    for (int i = 0; i < 3; ++i) {
        a[++tot] = id[1 + i];
        a[++tot] = id[n - i];
    }
    
    stable_sort(a + 1, a + tot + 1);
    tot = unique(a + 1, a + tot + 1) - a;
    
    ll ans = -1;
    for (int i = 1; i < tot; ++i)
        for (int j = i + 1; j < tot; ++j)
            for (int k = j + 1; k < tot; ++k) {
                ansminx = minx;
                ansmaxx = maxx;
                ansminy = miny;
                ansmaxy = maxy;
                for (int tmp = 1; tmp < tot; ++tmp)
                    if (tmp != i && tmp != j && tmp != k) {
                        ansminx = min(ansminx, x[a[tmp]]);
                        ansmaxx = max(ansmaxx, x[a[tmp]]);
                        ansminy = min(ansminy, y[a[tmp]]);
                        ansmaxy = max(ansmaxy, y[a[tmp]]);
                    }
                if ((ansminx >= ansmaxx) || (ansminy >= ansmaxy))
                    ans = 0;
                else
                    if (ans == -1)
                        ans = 1ll * (ansmaxx - ansminx) * (ansmaxy - ansminy);
                    else
                        ans = min(ans, 1ll * (ansmaxx - ansminx) * (ansmaxy - ansminy));
            }
    
    printf("%lld\n", ans);
    return 0;
}

转载于:https://www.cnblogs.com/abclzr/p/6069513.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值