POJ1259

给定平面上100个点 求一个最大的凸包,使得它不包含其中任意点,且凸包的顶点是题目所给的点。

枚举凸包左下角的点,顺时针枚举第二个点, 用opt[i][j]记录 i作为第二个点, 且第三个点k在向量i->j的右手(保持凸性)

显然相邻的凸包可以用来转移, opt[j][h]可以加入opt[i][j]  大致思想就是这样 看Solve函数。

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std; const int maxn=100;
const double zero=1e-8;
struct Vector
{
double x,y;
}; inline Vector operator -(Vector a,Vector b)
{
Vector c;
c.x=a.x-b.x;
c.y=a.y-b.y;
return c;
} inline double sqr(double a)
{
return a*a;
} inline int Sign(double a)
{
if(fabs(a)<=zero)return 0;
return a<0 ? -1:1;
} inline bool operator <(Vector a,Vector b)
{
return Sign(b.y-a.y)>0||Sign(b.y-a.y)==0&&Sign(b.x-a.x)>0; } inline double Max(double a,double b)
{
return a>b ? a:b;
} inline double Length(Vector a)
{
return sqrt(sqr(a.x)+sqr(a.y));
} inline double Cross(Vector a,Vector b)
{
return a.x*b.y-a.y*b.x;
} Vector dot[maxn],List[maxn];
double opt[maxn][maxn];
int seq[maxn];
int n,len;
double ans; bool Compare(Vector a,Vector b)
{
int temp=Sign(Cross(a,b));
if (temp!=0)return temp>0;
temp=Sign(Length(b)-Length(a));
return temp>0;
} void Solve(int vv)
{
int t,i,j,_len;
for(int ii=len=0;ii<n;ii++)
{
if(dot[vv]<dot[ii])List[len++]=dot[ii]-dot[vv];
}
for(i=0;i<len;i++)
for(j=0;j<len;j++)
opt[i][j]=0;
sort(List,List+len,Compare);
double v;
for(t=1;t<len;t++)
{
_len=0;
for(i=t-1;i>=0&&Sign(Cross(List[t],List[i]))==0;i--);
//cout<<i<<endl;
while(i>=0)
{
v=Cross(List[i],List[t])/2.;
seq[_len++]=i;
for(j=i-1;j>=0&&Sign(Cross(List[i]-List[t],List[j]-List[t]))>0;j--);
if(j>=0)v+=opt[i][j];
ans=Max(ans,v);
opt[t][i]=v;
i=j;
}
for(i=_len-2;i>=0;i--)
opt[t][seq[i]]=Max(opt[t][seq[i]],opt[t][seq[i+1]]);
}
} int i;
double Empty()
{
ans=0;
for(i=0;i<n;i++)
Solve(i);
return ans;
}
int main()
{freopen("t.txt","r",stdin);
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%lf%lf",&dot[i].x,&dot[i].y);
printf("%.1lf\n",Empty());
}
return 0;
}

  

POJ1259 The Picnic 最大空凸包问题 DP的更多相关文章

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

    题目大意: 给定n个点 求出这n个点中最大空凸包的面积 只放个模板 一份模板过两题(滑稽 这个讲解够详细了 https://blog.csdn.net/nyroro/article/details/4 ...

  2. hdu6219 Empty Convex Polygons (最大空凸包板子

    https://vjudge.net/contest/324256#problem/L 题意:给一堆点,求最大空凸包面积. 思路:枚举凸包左下角点O,dp找出以这个点为起始位置能构成的最大空凸包面积, ...

  3. ZOJ 3537 Cake(凸包+区间DP)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3537 题目大意:给出一些点表示多边形顶点的位置,如果不是凸多边形 ...

  4. HDU 3045 Picnic Cows(斜率优化DP)

    Picnic Cows Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...

  5. UOJ#7. 【NOI2014】购票 | 线段树 凸包优化DP

    题目链接 UOJ #7 题解 首先这一定是DP!可以写出: \[f[i] = \min_{ancestor\ j} \{f[j] + (d[j] - d[i]) * p[i] + q[i]\}\] 其 ...

  6. ZOJ 3537 Cake 求凸包 区间DP

    题意:给出一些点表示多边形顶点的位置(如果多边形是凹多边形就不能切),切多边形时每次只能在顶点和顶点间切,每切一次都有相应的代价.现在已经给出计算代价的公式,问把多边形切成最多个不相交三角形的最小代价 ...

  7. ZOJ - 3537 Cake (凸包+区间DP+最优三角剖分)

    Description You want to hold a party. Here's a polygon-shaped cake on the table. You'd like to cut t ...

  8. hdu6219(最大空凸包)

    题意: 给一些点,求出一个最大的空凸包,这个凸包里没有任何给定点且要求这个凸包面积最大 分析: 枚举凸包左下角的点,然后dp[i][j]表示凸包的最后两条边是j->i和i->O情况下凸包的 ...

  9. Cake(凸包+区间DP)

    You want to hold a party. Here's a polygon-shaped cake on the table. You'd like to cut the cake into ...

随机推荐

  1. win10永久激活

    现在我们可以看下当前系统的激活状态,查看方法"WIN+R"打开运行对话框,输入命令slmgr.vbs -xpr,点击确定,这样可以查看到当前系统的激活信息.大家可以发现,虽然小编系 ...

  2. c++基础_矩阵乘法

    #include <iostream> using namespace std; int main(){ int a,b; cin>>a>>b; long c[a] ...

  3. 输出一定范围unicode对应符号

    #本程序没有考虑对0x的处理,请勿输入,直接输入16进制位即可 begin = input("起始点:") end = input("结束点:") b_int0 ...

  4. tyvj1045 最大的算式

    描述 题目很简单,给出N个数字,不改变它们的相对位置,在中间加入K个乘号和N-K-1个加号,(括号随便加)使最终结果尽量大.因为乘号和加号一共就是N-1个了,所以恰好每两个相邻数字之间都有一个符号.例 ...

  5. Thinkphp5.0 的视图view的模板布局

    Thinkphp5.0 的视图view的模板布局 使用include,文件包含: <!-- 头部 --> <div class="header"> {inc ...

  6. POJ 3169_Layout

    大早上水一发=.= 题意: n头牛按编号顺序站成一列,给定n头牛之间的位置关系,求出第n头牛和第一头牛之间的最大距离. 分析: 差分约束系统,这题不等式关系还是挺好找的.注意因为按照顺序排列,所以有d ...

  7. Linux下tomcat的catalina.out屏蔽

    修改catalina.sh ,找到下面的位置: if [ -z "$CATALINA_OUT" ] ; then#CATALINA_OUT="$CATALINA_BASE ...

  8. 关于Java函数不支持参数默认值的讨论,最后一条亮了 2333

  9. no matching function transform?

    http://stackoverflow.com/questions/19876746/stdtolower-and-visual-studio-2013 http://forums.codeguru ...

  10. 在Windows上安装Nexus

    在Windows上安装Nexus 学习了:https://www.cnblogs.com/yucongblog/p/6696736.html 下载地址:https://sonatype-downloa ...