Processing math: 100%

【BZOJ 4581】【Usaco2016 Open】Field Reduction

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

#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;
}
posted @   abclzr  阅读(152)  评论(0编辑  收藏  举报
编辑推荐:
· .NET制作智能桌面机器人:结合BotSharp智能体框架开发语音交互
· 软件产品开发中常见的10个问题及处理方法
· .NET 原生驾驭 AI 新基建实战系列:向量数据库的应用与畅想
· 从问题排查到源码分析:ActiveMQ消费端频繁日志刷屏的秘密
· 一次Java后端服务间歇性响应慢的问题排查记录
阅读排行:
· 互联网不景气了那就玩玩嵌入式吧,用纯.NET开发并制作一个智能桌面机器人(四):结合BotSharp
· Vite CVE-2025-30208 安全漏洞
· 《HelloGitHub》第 108 期
· MQ 如何保证数据一致性?
· 一个基于 .NET 开源免费的异地组网和内网穿透工具
点击右上角即可分享
微信分享提示