HDU 3934
/*这是用的有旋转卡壳的思想。
首先确定i,j,对k进行循环,知道找到第一个k使得cross(i,j,k)>cross(i,j,k+1),如果k==i进入下一次循环。
对j,k进行旋转,每次循环之前更新最大值,然后固定一个j,同样找到一个k使得cross(i,j,k)>cross(i,j,k+1)。对j进行++操作,继续进行下一次,
知道j==k为止。
*/ #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath> using namespace std; struct point{
double x,y;
}p[1000100];
int n; int ans[1000100],st[1000100],cnt,stop; bool cmp(point A, point B){
if(A.y<B.y) return true;
else if(A.y==B.y){
if(A.x<B.x) return true;
}
return false;
} double multi(point a,point b,point c){
point p1; p1.x=a.x-c.x; p1.y=a.y-c.y;
point p2; p2.x=b.x-c.x; p2.y=b.y-c.y;
return p1.x*p2.y-p1.y*p2.x;
} void slove(){
cnt=stop=0;
st[stop++]=0; st[stop++]=1;
for(int i=2;i<n;i++){
while(stop>1&&multi(p[i],p[st[stop-1]],p[st[stop-2]])>=0) stop--;
st[stop++]=i;
}
for(int i=0;i<stop;i++)
ans[cnt++]=st[i];
stop=0; st[stop++]=n-1; st[stop++]=n-2;
for(int i=n-3;i>=0;i--){
while(stop>1&&multi(p[i],p[st[stop-1]],p[st[stop-2]])>=0) stop--;
st[stop++]=i;
}
for(int i=1;i<stop-1;i++)
ans[cnt++]=st[i];
/* for(int i=0;i<cnt;i++)
cout<<ans[i]<<endl;
cout<<endl;*/
} double Triangle(point a,point b,point c){
point p1; p1.x=a.x-c.x; p1.y=a.y-c.y;
point p2; p2.x=b.x-c.x; p2.y=b.y-c.y;
return fabs((p1.x*p2.y-p1.y*p2.x)*1.0)/2.0;
} double Area(){
int q; int j;
double anst=0;
for(int i=0;i<cnt;i++){
j=(i+1)%cnt;
q=(j+1)%cnt;
while(Triangle(p[ans[i]],p[ans[j]],p[ans[q]])<=Triangle(p[ans[i]],p[ans[j]],p[ans[(q+1)%cnt]])&&q!=i)
q=(q+1)%cnt; //枚举了当前最远的K点
anst=max(anst,Triangle(p[ans[i]],p[ans[j]],p[ans[q]]));
if(q==i) continue;
while(j!=i&&q!=i){
anst=max(anst,Triangle(p[ans[i]],p[ans[j]],p[ans[q]]));
while(Triangle(p[ans[i]],p[ans[j]],p[ans[q]])<=Triangle(p[ans[i]],p[ans[j]],p[ans[(q+1)%cnt]])&&q!=i)
q=(q+1)%cnt;
j=(j+1)%cnt;
} }
return anst;
} int main(){
while(scanf("%d",&n)!=EOF){
// if(n==-1) break;
for(int i=0;i<n;i++){
scanf("%lf%lf",&p[i].x,&p[i].y);
}
sort(p,p+n,cmp);
slove();
double anst=0;
anst=max(anst,Area());
printf("%.2lf\n",anst);
}
return 0;
}
HDU 3934的更多相关文章
- hdu 3934 Summer holiday (凸包+旋转卡壳)
Problem - 3934 晚上为了演示给师弟看水平序的凸包是多么的好写,于是就随便找了一题凸包,25min居然1y掉了.. 代码如下: #include <cmath> #includ ...
- hdu 3934&&poj 2079 (凸包+旋转卡壳+求最大三角形面积)
链接:http://poj.org/problem?id=2079 Triangle Time Limit: 3000MS Memory Limit: 30000K Total Submissio ...
- hdu 3934 Summer holiday(凸包最大内接三角形)
求n个点能组成的最大三角形,一发旋转卡壳模板题... #include<algorithm> #include<iostream> #include<cstring> ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
- HDU 1796How many integers can you find(容斥原理)
How many integers can you find Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
随机推荐
- bzoj4004 [JLOI2015]装备购买——线性基+贪心
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4004 今天讲课讲到的题,据说满足拟阵的性质,所以贪心是正确的: 总之就贪心,按价格从小到大排 ...
- A Reusable Aspect for Memory Profiling
例子: malPro.acc文件: #include <stdlib.h> size_t totalMemoryAllocated; int totalAllocationFuncCall ...
- ie8 不支持 position:fixed 的简单解决办法
今天发现使用 position:fixed 的页面在firefox下没有问题,在IE8下却不能正常显示,在网上找了找,有不少相关文章,但是不是不起作用就是太复杂,后来终于发现一个简单的解决办法,就是在 ...
- POJ 1118 求平面上最多x点共线
题意:给你n个点的坐标.求一条直线最多能穿过多少个点. 思路:枚举(n^2)+求斜率+排序 (复杂度n^2logn)大功告成 //By: Sirius_Ren #include <cmath&g ...
- [转]深入javascript——构造函数和原型对象
对象,是javascript中非常重要的一个梗,是否能透彻的理解它直接关系到你对整个javascript体系的基础理解,说白了,javascript就是一群对象在搅..(哔!). 常用的几种对象创建模 ...
- Clustered Index Scan 与 Clustered Index Seek
Clustered Index Scan 与 Clustered Index Seek 在利用 SQL Server 查询分析器的执行计划中,会有许多扫描方式,其中就有 Clustered Index ...
- ★Java语法(六)——————————分支语句
1. if 语句 格式用法: if(布尔表达式) { 语句: } 2. if……else 语句 格式用法: if(表达式) { 语句1: } else { 语句2: } 3.if……else i ...
- AdaBoost--从原理到实现(Code:Python)
本文对原文有修改,若有疑虑,请移步原作者. 原文链接:blog.csdn.net/dark_scope/article/details/14103983 集成方法在函数模型上等价于一个多层神经网络, ...
- ubuntu 16.04 安装QT问题
使用 sudo sh ./**.run 有错误: 增加 文件的可运行权限: sudo chmod +x Qt.run 直接运行: ./Qt.run 可完成安装
- .NET 解决方案 核心库整理
一系列令人敬畏的.NET核心库,工具,框架和软件: https://www.cnblogs.com/weifeng123/p/11039345.html 企业级解决方案收录: https://www ...