题目链接: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的更多相关文章

  1. HDU 5473 There was a kingdom 凸包 DP

    题意: 给出平面上n个点的坐标,选k个点,使得这k个点围起来的面积最大. 分析: 参考了 叉姐的分析 和 不慌不忙菊苣的代码 思路我都懂,但是DP的部分还是不太会写. 我体会了一下其中含义,也许这样可 ...

  2. Matrix Swapping II(求矩阵最大面积,dp)

    Matrix Swapping II Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  3. POJ 3178 凸包+DP (巨坑)

    题意: 思路: 这题巨坑!!! 这题巨坑!!! 这题巨坑!!! 这题巨坑!!! 这题巨坑!!! (而且没有题解--.5555555--) 只能照着自己想的写了-- 先求出来凸包 求凸包的方法呢:先找出 ...

  4. 暴力/DP Codeforces Beta Round #22 (Div. 2 Only) B. Bargaining Table

    题目传送门 /* 题意:求最大矩形(全0)的面积 暴力/dp:每对一个0查看它左下的最大矩形面积,更新ans 注意:是字符串,没用空格,好事多磨,WA了多少次才发现:( 详细解释:http://www ...

  5. 2017ACM-ICPC沈阳区域赛

    I-Little Boxes[大数] hdu6225  http://acm.hdu.edu.cn/showproblem.php?pid=6225 题意: 就是给四个大数,输出和. 思路: java ...

  6. Learning Vector

    题意: 给出n组x,y增量,从(0,0)开始以x,y坐标增加后等到的终点坐标,可以构成一个面积,再以这个终点为起点再增加,以此类推,使用增量顺序不同,得到的面积不,求用k组增量能得到的最大的面积. 分 ...

  7. FAB、TextInputLayout及Snackbar笔记

    FloatingActionButton 由于FloatingActionButton是重写ImageView的,所有FloatingActionButton拥有ImageView的一切属性. 控制F ...

  8. P2216 [HAOI2007]理想的正方形

    题目描述 有一个a*b的整数组成的矩阵,现请你从中找出一个n*n的正方形区域,使得该区域所有数中的最大值和最小值的差最小. 输入输出格式 输入格式: 第一行为3个整数,分别表示a,b,n的值 第二行至 ...

  9. 某考试 T2 yja

    2.1 Description 在平面上找 n 个点, 要求这 n 个点离原点的距离分别为 r1, r2, ..., rn. 最大化这 n 个点构成的凸包面积, 凸包上的点的顺序任意. 2.2 Inp ...

随机推荐

  1. RCC 2014 Warmup (Div. 2) ABC

    题目链接 A. Elimination time limit per test:1 secondmemory limit per test:256 megabytesinput:standard in ...

  2. perl杂项

    perl -pi -e 's|googleapis.com|useso.com|g' `find ./ -type f` yingc@yingc:~/gcyin/test/thirdparty/ffm ...

  3. nginx面试题

    1.Nginx是如何实现高并发的 service nginx start之后,然后输入#ps -ef|grep nginx,会发现Nginx有一个master进程和若干个worker进程,这些work ...

  4. SPRING IN ACTION 第4版笔记-第九章Securing web applications-003-把用户数据存在数据库

    一. 1.It’s quite common for user data to be stored in a relational database, accessed via JDBC . To c ...

  5. photoshop:制作木板木纹

    1.设置颜色为木头相近颜色 2.滤镜->渲染->云彩 3.滤镜->杂色->添加杂色 4.滤镜->模糊->动感模糊 5.用矩形选取选取某块区域 6.滤镜->扭曲 ...

  6. SQLite设置主键自动增长及插入语法

    SQLite中,一个自增长字段定义为INTEGER PRIMARY KEY AUTOINCREMENT,那么在插入一个新数据时,只需要将这个字段的值指定为NULL,即可由引擎自动设定其值,引擎会设定为 ...

  7. MySQL追加注释或者大量修改注释

     MySQL追加注释或者大量修改注释 2016-01-25 20:28:05 分类: MySQL MySQL 5.6.14 之前一个项目比较仓促,开发给的建表语句没有注释.现在要补全注释信息.但是My ...

  8. 关于Firefox浏览器如何支持ActiveX控件,一个小的Hellow World

    今天尝试开发一个Firefox的插件.虽然比较简单,网上也有很多教程,但是感觉一些教程写的比较麻烦,在初步的开发过程中并没有用到那些东西,于是自己把开发过程记录下来.我是根据Mozilla官方教程开发 ...

  9. 【HDOJ】4043 FXTZ II

    1. 题目描述有n个球,第i个球的伤害值为$2^i-1, i \in [1,n]$.有甲乙两个人,每次由甲选择n个球中的一个,用它以相同概率攻击自己或者乙,同时彻底消耗这个球.这样的攻击最多进行n次. ...

  10. 【HDOJ】3553 Just a String

    后缀数组加二分可解. /* 3553 */ #include <iostream> #include <sstream> #include <string> #in ...