HDU 6219 Empty Convex Polygons(最大空凸包)

#include <algorithm>
#include  <iostream>
#include   <cstdlib>
#include   <cstring>
#include    <cstdio>
#include    <string>
#include    <vector>
#include    <bitset>
#include     <stack>
#include     <cmath>
#include     <deque>
#include     <queue>
#include      <list>
#include       <set>
#include       <map>
#define mem(a, b) memset(a, b, sizeof(a))
#define pi acos(-1)
using namespace std;
typedef long long ll;
const int  inf = 0x3f3f3f3f;
const int maxn = 105;

struct Point{
	int x, y;
	Point(){};
	Point(int x, int y):x(x), y(y){};
	Point operator + (const Point &a){
		return Point(x+a.x, y+a.y); 
	}
	Point operator - (const Point &a){
		return Point(x-a.x, y-a.y); 
	}
	int operator * (const Point &a){
		return x*a.y - y*a.x;
	}
	int len() const {
		return x*x+y*y;
	}
	bool const operator < (const Point &a){
		if((*this)*a > 0 || (*this)*a == 0 && len() < a.len()){
			return 1;
		}
		return 0;
	}
}point1[maxn], point2[maxn];
int dp[maxn][maxn];

int jud(int m){
	int ans = 0;
	mem(dp, 0);
	for(int i = 2; i <= m; i++){
		int now = i-1;
		while(now >= 1 && point2[i]*point2[now] == 0){
			now--;
		}
		int flag = 0;
		if(now == i-1){
			flag = 1;
		}
		while(now >= 1){
			int S = point2[now]*point2[i], k = now-1;
			while(k >= 1 && (point2[now]-point2[i])*(point2[k]-point2[now]) > 0){
				k--;
			}
			if(k >= 1){
				S += dp[now][k];
			}
			if(flag){
				dp[i][now] = S;
			}
			ans = max(ans, S);
			now = k;
		}
		if(!flag){
			continue;
		}
		for(int j = 1; j <= i-1; j++){
			dp[i][j] = max(dp[i][j], dp[i][j-1]);
		}
	}
	return ans;
}

int main(){
	int t;
	scanf("%d", &t);
	while(t--){
		int n;
		scanf("%d", &n);
		for(int i = 1; i <= n; i++){
			scanf("%d %d", &point1[i].x, &point1[i].y);
		}
		int ans = 0;
		for(int i = 1; i <= n; i++){
			int m = 0;
			for(int j = 1; j <= n; j++){
				if(point1[j].y > point1[i].y || point1[j].y == point1[i].y && point1[j].x >= point1[i].x){
					point2[++m] = point1[j] - point1[i];
				} 
			}
			sort(point2+1, point2+m+1);
			ans = max(ans, jud(m));
		}
		printf("%.1lf\n", ans/2.0);
	}
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值