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);
	}
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章