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之Pycharm安装及介绍
在学习Python之前,先安装好编程所需的编译环境也就是IDE,在安装PycharPm之前先安装最新版本的anaconda根据不同的系统选择不同的版本,安装好anaconda以后再安装Pycharm, ...
- 84-Market Facilitation Index 市场促进指数指标.(2015.7.3)
Market Facilitation Index 市场促进指数指标 MFI指标的计算方式为: MFI=High(最高价)-Low(最低价))/ Volume(成交量) MFI上升,成交量上升,表示价 ...
- LeetCode(49)Group Anagrams
题目 Given an array of strings, group anagrams together. For example, given: ["eat", "t ...
- angular2集成highchart
集成highchart的配置困扰了我很久,今天终于解决了: 1.修改tsconfig.app.json: "compilerOptions": { //... "type ...
- ..net 3.5新特性之用this关键字为类添加扩展方法
具体用法如下: public static class ClassHelper { //用this 声明将要吧这个方法附加到Student对象 public static bool CheckName ...
- bzoj 3173 [Tjoi2013]最长上升子序列 (treap模拟+lis)
[Tjoi2013]最长上升子序列 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 2213 Solved: 1119[Submit][Status] ...
- 【bzoj2152】聪聪可可 点分治
[bzoj2152]聪聪可可 2014年9月7日3,5472 Description 聪聪和可可是兄弟俩,他们俩经常为了一些琐事打起来,例如家中只剩下最后一根冰棍而两人都想吃.两个人都想玩儿电脑(可是 ...
- [ C++ 快速高精度模板 ] [ BigN类 ] 大整数类 高精度 模板 BigInt FFT 快速傅里叶变换
[原创 转载请注明]瞎写的,如果代码有错,或者各位大佬有什么意见建议,望不吝赐教 更新日志: 对于规模较小的整数乘法使用$$O(n^2)$$方法,提高速度 modify()和operator[]的bu ...
- 洛谷 通天系列 P1760 P1757 P1759
P1760 通天之汉诺塔 汉诺塔问题.一个高精乘单精解决 ans=2^n-1 /*by SilverN*/ #include<algorithm> #include<iostream ...
- 【POJ3680】Intervals(费用流)
题意:有n条线段,每条有起点,终点和一个权值 要求选取一些线段,使它们的权值和最大,并且使每一个点被覆盖不超过k次 1 ≤ K ≤ N ≤ 200 1 ≤ ai < bi ≤ 100,000, ...