HUOJ-10857 最大的面积 凸包+DP
题目链接:http://acm.hunnu.edu.cn/online/?action=problem&type=show&id=10857&courseid=55
比赛的时候把题目看成取恰好K个点了,,,悲剧。。然后按照正确的题意的话,是比较好做的,求个凸包,然后DP就可以了,f[i][j][k]表示第 i 个点到第 j 点选择k个点的多边形的最大面积,那么f[i][j][k]=Max{ f[i][j][k], f[i][y][k-1]+area(p[i],p[y],p[j]) }就可以了。。
这题相当悲剧,题目的数据范围描述错了,k应该是小于等于30,因为题目sb,看了一晚上的代码= =!
//STATUS:C++_AC_0MS_1284KB
#include <functional>
#include <algorithm>
#include <iostream>
//#include <ext/rope>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,102400000")
//using namespace __gnu_cxx;
//define
#define pii pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define PI acos(-1.0)
//typedef
typedef long long LL;
typedef unsigned long long ULL;
//const
const int N=;
const int INF=0x3f3f3f3f;
const int MOD=,STA=;
const LL LNF=1LL<<;
const double EPS=1e-;
const double OO=1e60;
const int dx[]= {-,,,};
const int dy[]= {,,,-};
const int day[]= {,,,,,,,,,,,,};
//Daily Use ...
//End struct point{
double x, y;
}p[N],res[N]; double f[N][N];
int T,n,k; bool mult(point sp, point ep, point op)
{
return (sp.x - op.x) * (ep.y - op.y)>= (ep.x - op.x) * (sp.y - op.y);
} bool operator < (const point &l, const point &r)
{
return l.y < r.y || (l.y == r.y && l.x < r.x);
} int graham(point pnt[], int n, point res[])
{
int i, len, k = , top = ;
sort(pnt, pnt + n);
if (n == ) return ;
res[] = pnt[];
if (n == ) return ;
res[] = pnt[];
if (n == ) return ;
res[] = pnt[];
for (i = ; i < n; i++){
while (top && mult(pnt[i], res[top], res[top-]))top--;
res[++top] = pnt[i];
}
len = top;
res[++top] = pnt[n - ];
for (i = n - ; i >= ; i--){
while (top!=len && mult(pnt[i], res[top], res[top-])) top--;
res[++top] = pnt[i];
}
return top; // 返回凸包中点的个数
} double arear(point& a,point& b,point& c)
{
double ret=;
ret+=a.x*b.y-a.y*b.x;
ret+=b.x*c.y-b.y*c.x;
ret+=c.x*a.y-c.y*a.x;
return ret/;
} int main()
{
// freopen("in.txt","r",stdin);
int i,j,x,y,cnt;
double ans;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&k);
for(i=; i<n; i++){
scanf("%lf%lf",&p[i].x,&p[i].y);
}
cnt=graham(p,n,res);
if(cnt<= || k<=){
printf("0.00\n");
continue;
}
if(cnt<=k){
double sum=;
for(i=;i<cnt;i++)
sum+=res[i].x*res[(i+)%cnt].y-res[i].y*res[(i+)%cnt].x;
printf("%.2lf\n",sum/=);
continue;
}
ans=;
int m=cnt;
while(m--){
mem(f,);
point t=res[];
for(j=;j<cnt-;j++)res[j]=res[j+];
res[j]=t;
for(j=;j<cnt;j++){
for(x=;x<=j+ && x<=k;x++){
for(y=x-;y<j;y++){
f[j][x]=max(f[j][x],f[y][x-]+arear(res[],res[y],res[j]));
}
}
ans=max(ans,f[j][k]);
}
} printf("%.2lf\n",ans);
}
return ;
}
HUOJ-10857 最大的面积 凸包+DP的更多相关文章
- HDU 5473 There was a kingdom 凸包 DP
题意: 给出平面上n个点的坐标,选k个点,使得这k个点围起来的面积最大. 分析: 参考了 叉姐的分析 和 不慌不忙菊苣的代码 思路我都懂,但是DP的部分还是不太会写. 我体会了一下其中含义,也许这样可 ...
- Matrix Swapping II(求矩阵最大面积,dp)
Matrix Swapping II Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- POJ 3178 凸包+DP (巨坑)
题意: 思路: 这题巨坑!!! 这题巨坑!!! 这题巨坑!!! 这题巨坑!!! 这题巨坑!!! (而且没有题解--.5555555--) 只能照着自己想的写了-- 先求出来凸包 求凸包的方法呢:先找出 ...
- 暴力/DP Codeforces Beta Round #22 (Div. 2 Only) B. Bargaining Table
题目传送门 /* 题意:求最大矩形(全0)的面积 暴力/dp:每对一个0查看它左下的最大矩形面积,更新ans 注意:是字符串,没用空格,好事多磨,WA了多少次才发现:( 详细解释:http://www ...
- 2017ACM-ICPC沈阳区域赛
I-Little Boxes[大数] hdu6225 http://acm.hdu.edu.cn/showproblem.php?pid=6225 题意: 就是给四个大数,输出和. 思路: java ...
- Learning Vector
题意: 给出n组x,y增量,从(0,0)开始以x,y坐标增加后等到的终点坐标,可以构成一个面积,再以这个终点为起点再增加,以此类推,使用增量顺序不同,得到的面积不,求用k组增量能得到的最大的面积. 分 ...
- FAB、TextInputLayout及Snackbar笔记
FloatingActionButton 由于FloatingActionButton是重写ImageView的,所有FloatingActionButton拥有ImageView的一切属性. 控制F ...
- P2216 [HAOI2007]理想的正方形
题目描述 有一个a*b的整数组成的矩阵,现请你从中找出一个n*n的正方形区域,使得该区域所有数中的最大值和最小值的差最小. 输入输出格式 输入格式: 第一行为3个整数,分别表示a,b,n的值 第二行至 ...
- 某考试 T2 yja
2.1 Description 在平面上找 n 个点, 要求这 n 个点离原点的距离分别为 r1, r2, ..., rn. 最大化这 n 个点构成的凸包面积, 凸包上的点的顺序任意. 2.2 Inp ...
随机推荐
- spoj 364
动规 f[i][j]表示第i到第j个数能取到的最大值 e[i][j]表示最小值 ....... #include <cstdio> #include <cstring> us ...
- zoj 2387
额 一个贪心 好难想到 ...... #include <cstring> #include <cstdio> #include <algorithm> #in ...
- JavaScript 三种创建对象的方法
JavaScript中对象的创建有以下几种方式: (1)使用内置对象 (2)使用JSON符号 (3)自定义对象构造 一.使用内置对象 JavaScript可用的内置对象可分为两种: 1,JavaScr ...
- java:I/O 根据用户输入反馈信息
import java.io.*; class userInputIO{ //Java中成员变量有默认初始化,也就是如果不显式设置初始值的话就会被初始化为其类型的默认值(0.false.null等). ...
- Git教程之删除文件(8)
在Git中,删除也是一个修改操作,我们实战一下,先添加一个新文件test.txt到Git并且提交:
- C3p0/元数据/内省-Bean/自定义查询封装类/查询/分页
c3p0连接池(C3p0连接池,只有当用户获取连接时,才会包装Connection.) 第一步:导入c3p0 第二步:在classpath目录下,创建一个c3p0-config.xml 第三步:创建工 ...
- [ffmpeg 扩展第三方库编译系列] frei0r mingw32 下编译问题
在编译安装frei0r的时候遇到两个错误地方, 两个都是在install的时候. 一开始编译都很顺利,输入了 make install之后就走开了,回来一看,报错误. 提示mkdir -p //usr ...
- Where is Vasya?
Where is Vasya? Vasya stands in line with number of people p (including Vasya), but he doesn't know ...
- vsphere client cd/dvd 驱动器1 正在连接
esxi 5.1选择了客户端设备,打开控制台后,CD/DVD一直显示“CD/DVD驱动器1 正在连接” 解决方法:vSphere Client客户端问题,关闭和重新打开vSphere Client客户 ...
- [转] 字符串模式匹配算法——BM、Horspool、Sunday、KMP、KR、AC算法一网打尽
字符串模式匹配算法——BM.Horspool.Sunday.KMP.KR.AC算法一网打尽 转载自:http://dsqiu.iteye.com/blog/1700312 本文内容框架: §1 Boy ...