标签:多边形面积 logs www. status memory namespace print http inpu
5 0 0 1 0 1 1 0 1 0.5 0.5
1.000
# include <iostream> # include <cstdio> # include <cstring> # include <cmath> # include <algorithm> using namespace std; struct data{ double x,y; }node[4003],s[4003]; int n,top; double ans; double dis(data a,data b){ return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); } double mul(data a,data b,data c){ return (a.x - c.x) * (b.y - c.y) - (b.x - c.x) * (a.y - c.y); } bool cmp(data a,data b) { if(mul(a,b,node[1]) == 0)return dis(a,node[1]) < dis(b,node[1]); return mul(a,b,node[1]) > 0; } void Graham(){ int k = 1; for(int i = 2;i <= n;i++) if((node[k].y > node[i].y) || (node[k].y == node[i].y && node[k].x > node[i].x))k = i; swap(node[k],node[1]); sort(node + 1,node + n + 1,cmp); s[++top] = node[1],s[++top] = node[2]; for(int i = 3;i <= n;i++){ while(top && mul(node[i],s[top],s[top - 1]) >= 0)top--; s[++top] = node[i]; } } void rc(){ s[top + 1] = node[1]; int a,b; for(int x = 1;x <= top;x++){ a = x % top + 1;b = (x + 2) % top + 1; for(int y = x + 2;y <= top;y++){ while(a % top + 1 != y && -mul(s[y],s[a + 1],s[x]) > -mul(s[y],s[a],s[x]))a = a % top + 1; while(b % top + 1 != x && -mul(s[b + 1],s[y],s[x]) > -mul(s[b],s[y],s[x]))b = b % top + 1; ans = max(-mul(s[y],s[a],s[x]) + -mul(s[b],s[y],s[x]),ans); } } } int main(){ scanf("%d",&n); for(int i = 1;i <= n;i++)scanf("%lf %lf",&node[i].x,&node[i].y); Graham();rc(); printf("%.3f",ans / 2); return 0; }
[Bzoj1069][Scoi2007]最大土地面积(凸包)(旋转卡壳)
标签:多边形面积 logs www. status memory namespace print http inpu
原文地址:http://www.cnblogs.com/lzdhydzzh/p/7642368.html