题意 :
给一块空地,上面有很多的树,让你求用树能为最大的 多边形
给一块空地,上面有很多的树,让你求用树能为最大的 多边形
思路:凸包, 求出凸包的顶点 计算多边形的面积:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
const int maxn = 1e4+5;
struct node
{
double x, y;
double rad;
}p[maxn], tp[maxn];
bool cmp1(node a, node b)
{
if(a.y == b.y) return a.x < b.x;
return a.y < b.y;
}
bool cmp2(node a, node b)
{
if(a.rad == b.rad) return a.x < b.x;
return a.rad < b.rad;
}
double rad_point(node a, node b)
{
return atan2((b.y-a.y), (b.x-a.x));
}
double sum_point(node a, node b)
{
return a.x*b.y-b.x*a.y;
}
bool tp_point(node a, node b, node c)
{
int m = (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);
if(m < 0) return true;
if(m > 0 || m == 0) return false;
}
int main()
{
int n;
while(scanf("%d", &n) != EOF)
{
for(int i = 0; i < n; i++) scanf("%lf%lf", &p[i].x, &p[i].y);
sort(p, p+n, cmp1);
for(int i = 0; i < n; i++) p[i].rad = rad_point(p[0], p[i]);
sort(p+1, p+n, cmp2);
tp[0] = p[0];
tp[1] = p[1];
tp[2] = p[2];
int top = 2;
for(int i = 3; i < n; i++)
{
while(top >= 1 && tp_point(tp[top-1], tp[top], p[i])) top--;
tp[++top] = p[i];
}
top++;
double sum = 0;
for(int i = 0; i < top; i++) sum += sum_point(tp[i%top], tp[(i+1)%top]);
int s = abs(sum/100);
printf("%d\n", s);
}
}