最大空凸包模板

inline double sgn(double x, double y)
{
    return fabs(x-y)<eps;
}

inline int sgn(int x, int y)
{
    return x==y;
}

struct point
{
    double x,y;
};

double cross(point a, point b, point o)
{
    return (a.x-o.x)*(o.y-b.y)-(a.y-o.y)*(o.x-b.x);
}

double dist(point a, point b)
{
    return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
point o;

bool cmp_angle(point a,point b)
{
    if(sgn(cross(a,b,o),0.0))
    {
        return dist(a,o)<dist(b,o);
    }
    return cross(a,o,b)>0;
}

double empty_convex(point p[], int pn)
{
    double ans=0;
    memset(dp,0,sizeof(dp));

    for(int i=0; i<pn; i++)
    {
        int j = i-1;
        while(j>=0 && sgn(cross(p[i], p[j], o),0.0)) j--;//coline

        bool flag= j==i-1;

        while(j>=0)
        {
            int k = j-1;
            while(k >= 0 && cross(p[i],p[k],p[j])>0) k--;
            double area = fabs(cross(p[i],p[j],o))/2;
            if(k >= 0)area+=dp[j][k];
            if(flag) dp[i][j]=area;
            ans=max(ans,area);
            j=k;
        }
        if(flag)
        {
            for(int j=1; j<i; j++)
            {
                dp[i][j] = max(dp[i][j],dp[i][j-1]);
            }
        }
    }
    return ans;
}

double largest_empty_convex(point p[], int pn)
{
    point data[maxn];
    double ans=0;
    for(int i=0; i<pn; i++)
    {
        o=p[i];
        int dn=0;
        for(int j=0; j<pn; j++)
        {
            if(p[j].y>o.y||(p[j].y==o.y&&p[j].x>=o.x))
            {
                data[dn++]=p[j];
            }
        }
        sort(data, data+dn, cmp_angle);
        ans=max(ans, empty_convex(data, dn));
    }
    return ans;
}
时间: 2024-10-10 09:03:03

最大空凸包模板的相关文章

O(n^3)求最大空凸包模板(2017沈阳icpc-C Empty Convex Polygons )

题目链接:https://vjudge.net/contest/358714#problem/C 题意:求最大空凸包的面积,点的个数n<=50. 思路: 参考链接:https://blog.csdn.net/cdsszjj/article/details/79366813 计算几何+DP. 首先枚举凸包最左下角的点O,忽略O下面的点,对其它点进行极角排序. 然后枚举凸包上的最后一个点i,用dp[i][j]表示以三角形Oij为凸包的最后一块三角形的最大空凸包的面积.那么可以得到转移方程: dp[i

Game of Taking Stones &amp;&amp; POJ1259 /// 最大空凸包 几何+DP

题目大意: 给定n个点 求出这n个点中最大空凸包的面积 只放个模板 一份模板过两题(滑稽 这个讲解够详细了 https://blog.csdn.net/nyroro/article/details/45268767 #include <stdio.h> #include <cstring> #include <cmath> #include <algorithm> using namespace std; const double eps=1e-8; dou

三维凸包模板

poj3528 参照 #include <cstring> #include <cstdio> #include <cmath> #include <algorithm> using namespace std; #define inf 0x7fffffff #define max(a,b) (a>b?a:b) #define min(a,b) (a<b?a:b) #define eps 1e-7 #define MAXV 505 //三维点 s

凸包模板 POJ1873

1 // 凸包模板 POJ1873 2 // n=15所以可以按位枚举求凸包,再记录数据 3 4 #include <iostream> 5 #include <cstdio> 6 #include <cstdlib> 7 #include <algorithm> 8 #include <vector> 9 #include <math.h> 10 using namespace std; 11 #define LL long lon

计算几何 --- 凸包 模板

//Memory Time // 1347K 0MS // by : Snarl_jsb #include<algorithm> #include<cstdio> #include<cstring> #include<cstdlib> #include<iostream> #include<vector> #include<queue> #include<stack> #include<map> #

POJ 1113 凸包模板题

上模板. #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <cmath> #include <vector> #include <utility> #include <stack> #include <queue> #include <map> #include

计算几何(凸包模板):HDU 1392

There are a lot of trees in an area. A peasant wants to buy a rope to surround all these trees. So at first he must know the minimal required length of the rope. However, he does not know how to calculate it. Can you help him? The diameter and length

(凸包模板)(刘汝佳)

struct point{ int x,y;} p[N],stack[N]; bool cmp(point A,point B){ if(A.y==B.y)return A.x<B.x; return A.y<B.y;}int cross(point A,point B,point C){ return (B.x-A.x)*(C.y-A.y)-(C.x-A.x)*(B.y-A.y);}void graham(){ sort(p,p+n,cmp); int i; top=0; for(i=0;

二维凸包模板

double cross(Point a,Point b) { return a.x*b.y-a.y*b.x; } double mul(Point p0,Point p1,Point p2) { return cross(p1-p0,p2-p0); } double dis(Point a) { return sqrt(a.x*a.x+a.y*a.y); } bool cmp(Point a,Point b) { if(dcmp(mul(p[0],a,b))==0) return dis(a-