POJ1259 The Picnic 最大空凸包问题 DP
给定平面上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的更多相关文章
- Game of Taking Stones && POJ1259 /// 最大空凸包 几何+DP
题目大意: 给定n个点 求出这n个点中最大空凸包的面积 只放个模板 一份模板过两题(滑稽 这个讲解够详细了 https://blog.csdn.net/nyroro/article/details/4 ...
- hdu6219 Empty Convex Polygons (最大空凸包板子
https://vjudge.net/contest/324256#problem/L 题意:给一堆点,求最大空凸包面积. 思路:枚举凸包左下角点O,dp找出以这个点为起始位置能构成的最大空凸包面积, ...
- ZOJ 3537 Cake(凸包+区间DP)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3537 题目大意:给出一些点表示多边形顶点的位置,如果不是凸多边形 ...
- HDU 3045 Picnic Cows(斜率优化DP)
Picnic Cows Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- UOJ#7. 【NOI2014】购票 | 线段树 凸包优化DP
题目链接 UOJ #7 题解 首先这一定是DP!可以写出: \[f[i] = \min_{ancestor\ j} \{f[j] + (d[j] - d[i]) * p[i] + q[i]\}\] 其 ...
- ZOJ 3537 Cake 求凸包 区间DP
题意:给出一些点表示多边形顶点的位置(如果多边形是凹多边形就不能切),切多边形时每次只能在顶点和顶点间切,每切一次都有相应的代价.现在已经给出计算代价的公式,问把多边形切成最多个不相交三角形的最小代价 ...
- 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 ...
- hdu6219(最大空凸包)
题意: 给一些点,求出一个最大的空凸包,这个凸包里没有任何给定点且要求这个凸包面积最大 分析: 枚举凸包左下角的点,然后dp[i][j]表示凸包的最后两条边是j->i和i->O情况下凸包的 ...
- 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 ...
随机推荐
- 关于ie8下disabled属性:字体颜色问题
在ie8下,input/textarea输入框如果使用disabled属性,字体的颜色会变灰,这时我们可以使用另一种方法实现它. 不使用disabled,用readonly代替: input[read ...
- PHP面向对象设计五大原则(SOLID)梳理总结
PHP设计原则梳理,参考<PHP核心技术与最佳实践>.<敏捷开发原则.模式与实践>,文章PHP面向对象设计的五大原则.设计模式原则SOLID 单一职责原则(Single Res ...
- win7 x64安装glpk
下载glpk,下载地址:http://ftp.gnu.org/gnu/glpk/
- POJ 1995 (快速幂) 求(A1B1+A2B2+ ... +AHBH)mod M
Description People are different. Some secretly read magazines full of interesting girls' pictures, ...
- 前端性能分析-HTTPWatch和dynaTrace
- java程序验证用户名密码和验证码登录的小例子
package Study02; import java.util.Random; import java.util.Scanner; public class test { static Strin ...
- Linux备份-删除指定日期内文件
#!/usr/bin/env bash source /etc/profile echo " *************** start filter *************** &q ...
- onos控制器通过REST API下发流表
onos控制器REST API地址:http://192.168.43.14:8181/onos/v1/docs/ stream书写格式: { "id": "675540 ...
- ***jQuery使用总结(原创)
Q: jquery选择器为变量时是怎么办 A: 一个变量我知道可以这样写:$("#"+id) Q: 如何清除单选框的checked属性 A: $("input[type= ...
- 洛谷—— P3386 【模板】二分图匹配
P3386 [模板]二分图匹配(复习) 题目背景 二分图 题目描述 给定一个二分图,结点个数分别为n,m,边数为e,求二分图最大匹配数 输入输出格式 输入格式: 第一行,n,m,e 第二至e+1行,每 ...