【bzoj1069】[SCOI2007]最大土地面积

1069: [SCOI2007]最大土地面积

Time Limit: 1 Sec   Memory Limit: 128 MB
Submit: 3673   Solved: 1454
[ Submit][ Status][ Discuss]

Description

  在某块平面土地上有N个点,你可以选择其中的任意四个点,将这片土地围起来,当然,你希望这四个点围成
的多边形面积最大。

Input

  第1行一个正整数N,接下来N行,每行2个数x,y,表示该点的横坐标和纵坐标。

Output

  最大的多边形面积,答案精确到小数点后3位。

Sample Input

5
0 0
1 0
1 1
0 1
0.5 0.5

Sample Output

1.000

HINT

数据范围 n<=2000, |x|,|y|<=100000

Source

[ Submit][ Status][ Discuss]



蒟蒻一开始居然想用

模拟退火= =

然而这样一道几何题怎么能模拟退火。。。

首先这题的最优四边形肯定有两个点在凸包上,那么我们考虑去枚举四边形的这两个点

观察到随着两个点的顺时针转动,另外两个最优的点也随着相应顺时针转动

于是可以旋转卡壳。。。

代码:
#include<cstdio>
#include<ctime>
#include<cstdlib>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;

typedef long long LL;
typedef double DL;

const int maxn = 2010;
const DL eps = 1e-9;

struct point{
	DL x,y; point(DL x = 0,DL y = 0): x(x),y(y){}
};

struct Vector{
	DL x,y; Vector(DL x = 0,DL y = 0): x(x),y(y){}
};

int n,top;
point p[maxn],stk[maxn];

inline int getint()
{
	int ret = 0;
	char c = getchar();
	while (c < '0' || '9' < c) c = getchar();
	while ('0' <= c && c <= '9')
		ret = ret * 10 + c - '0',c = getchar();
	return ret;
}

inline DL cross(Vector a,Vector b)
{
	return a.x * b.y - b.x * a.y;
}

inline Vector link(point a,point b)
{
	return (Vector){a.x - b.x,a.y - b.y};
}

inline DL sqr(DL x)
{
	return x * x;
}

inline DL dis(point a,point b)
{
	return sqrt(sqr(a.x - b.x) + sqr(a.y - b.y));
}

inline bool cmp(point a,point b)
{
	DL tmp = cross(link(a,p[1]),link(b,p[1]));
	if (tmp == 0) return dis(a,p[1]) < dis(b,p[1]);
	return tmp < 0;
}

inline void hull()
{
	int to = 1;
	for (int i = 2; i <= n; i++)
		if (p[to].y > p[i].y || (p[to].y == p[i].y && p[to].x > p[i].x))
			to = i;
	swap(p[1],p[to]);
	sort(p + 2,p + n + 1,cmp);
	for (int i = 1; i <= n; i++)
	{
		while (top >= 2 && cross(link(p[i],stk[top - 1]),link(stk[top],stk[top - 1])) <= 0) 
			top--;
		stk[++top] = p[i];
	}
}

inline DL solve()
{
	DL ans = 0;
	for (int i = 1; i <= top; i++)
	{
		int a = i,b = i + 2;
		for (int j = i + 2; j <= top; j++)
		{
			while (cross(link(stk[a % top + 1],stk[i]),link(stk[j],stk[i])) < cross(link(stk[a],stk[i]),link(stk[j],stk[i])))
				a = a % top + 1;
			while (cross(link(stk[b % top + 1],stk[j]),link(stk[i],stk[j])) < cross(link(stk[b],stk[j]),link(stk[i],stk[j])))
				b = b % top + 1;
			ans = max(ans, - cross(link(stk[a],stk[i]),link(stk[j],stk[i])) + cross(link(stk[b],stk[i]),link(stk[j],stk[i])));
		}
	}
	return ans / 2;
}

int main()
{
	n = getint();
	for (int i = 1; i <= n; i++)
		scanf("%lf%lf",&p[i].x,&p[i].y);
	hull();
	printf("%.3lf",solve());
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值