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 ...
随机推荐
- python 安装模块 更新模块
#显示模块pip list #显示过期模块pip list --outdated #安装模块pip install xxx #升级模块pip install --upgrade xxx
- Django-rest_framework中利用jwt登录验证时,自定义返回凭证和登录校验支持手机号
安装 pip install djangorestframework-jwt 在Django.settings中配置 REST_FRAMEWORK = { 'DEFAULT_AUTHENTICATIO ...
- HTML文件中css样式的引用
1.1.直接在div中使用css样式制作div+css网页 如: <div style="font-size:14px; color:#FF0000;">内容</ ...
- tarjan 割点 割边
by GeneralLiu tarjan 求 割点 割边 无向图 的 割点 割边: 对于无向连通图来说, 如果删除 一个点以及与它相连的边 之后, 使得这个图不连通, 那么该点为割点 : ...
- 静态区间第k大(划分树)
POJ 2104为例[经典划分树问题] 思想: 利用快速排序思想, 建树时将区间内的值与区间中值相比,小于则放入左子树,大于则放入右子树,如果相等则放入左子树直到放满区间一半. 查询时,在建树过程中利 ...
- Ubuntu 16.04安装Ubuntu After Install工具实现常用软件批量安装
这个软件集成了常用且好用的软件,且只需要选择需要的软件之后自动安装好,不需要额外设置. 安装: sudo add-apt-repository ppa:thefanclub/ubuntu-after- ...
- HAProxy+Redis实现负载负载均衡(待实践)
为什么要使用HA,原因是可以聚合出一个VIP,也就是可以使用单一IP来访问下面多个Redis的实例. 首先说明一下,如果基于3.0以后搭建的官方原始Redis Cluster方案,使用HAProxy是 ...
- how to read openstack code: Neutron architecture
今天这一章节非常重要.我们知道neutron是一个非常复杂的系统,由很多组件构成.研究这样一个复杂的系统,正确的顺序应该是现在宏观上对其整体结构有所了解,然后再由针对性的对其组件进行深入了解.本章要做 ...
- Centos7 samba 匿名共享 简单config
安装Samba yum install samba samba-client samba-common -y 备份原始的Samba配置文件: mv /etc/samba/smb.conf /etc/s ...
- webpack-入口篇
入口起点[Entry Points]: 单个入口(简写)语法 用法:entry: string|Array<string> 例子(webpack.config.js) const conf ...