http://poj.org/problem?id=2079

题目大意:求最大面积的三角形。

——————————————————

可以知道,最大面积的三角形的顶点一定是最大凸包的顶点。

接下来就是O(n*n)的常数优化题了(利用单峰性)。

(但其实不是n*n的,因为我们求的是纯凸包,所以n会小一些)

#include<cstdio>
#include<queue>
#include<cctype>
#include<cstring>
#include<stack>
#include<cmath>
#include<algorithm>
using namespace std;
typedef double dl;
const dl eps=1e-;
const int N=;
struct point{
dl x;
dl y;
}p[N],q[N];
int n,per[N],l;
inline point getmag(point a,point b){
point s;
s.x=b.x-a.x;s.y=b.y-a.y;
return s;
}
inline dl multiX(point a,point b){
return a.x*b.y-b.x*a.y;
}
inline dl dis(point a,point b){
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
inline bool cmp(int u,int v){
dl det=multiX(getmag(p[],p[u]),getmag(p[],p[v]));
if(fabs(det)>eps)return det>eps;
return dis(p[],p[u])-dis(p[],p[v])<-eps;
}
void graham(){
int id=;
for(int i=;i<=n;i++){
if(p[i].x-p[id].x<-eps||(fabs(p[i].x-p[id].x)<eps&&p[i].y-p[id].y<-eps))id=i;
}
if(id!=)swap(p[],p[id]);
for(int i=;i<=n;i++)per[i]=i;
sort(per+,per+n+,cmp);
l=;
q[++l]=p[];
for(int i=;i<=n;i++){
int j=per[i];
while(l>=&&multiX(getmag(q[l-],p[j]),getmag(q[l-],q[l]))>-eps){
l--;
}
q[++l]=p[j];
}
return;
}
inline dl area(){
if(l<=)return ;
dl ans=;
for(int i=;i<=l;i++){
int j=i%l+;
int k=j%l+;
while(){
dl s1=multiX(getmag(q[i],q[j]),getmag(q[i],q[k]));
dl s2=multiX(getmag(q[i],q[j]),getmag(q[i],q[k%l+]));
if(fabs(s1)-fabs(s2)>-eps){
break;
}
k=k%l+;
}
while(i!=j&&j!=k&&i!=k){
dl s=multiX(getmag(q[i],q[j]),getmag(q[i],q[k]));
ans=max(ans,fabs(s)/2.0);
while(){
dl s1=multiX(getmag(q[i],q[j]),getmag(q[i],q[k]));
dl s2=multiX(getmag(q[i],q[j]),getmag(q[i],q[k%l+]));
if(fabs(s1)-fabs(s2)>-eps){
break;
}
k=k%l+;
}
j=j%l+;
}
}
return ans;
}
int main(){
while(scanf("%d",&n)!=EOF&&n!=-){
for(int i=;i<=n;i++)scanf("%lf%lf",&p[i].x,&p[i].y);
graham();
printf("%.2f\n",area());
}
return ;
}

POJ2079:Triangle——题解的更多相关文章

  1. ZOJ 4081 Little Sub and Pascal's Triangle 题解

    ZOJ 4081 Little Sub and Pascal's Triangle 题解 题意 求杨辉三角第n行(从1开始计数)有几个奇数. 考察的其实是杨辉--帕斯卡三角的性质,或者说Gould's ...

  2. codechef Sums in a Triangle题解

    Let's consider a triangle of numbers in which a number appears in the first line, two numbers appear ...

  3. POJ2079 Triangle

    题面 题解 我什么时候会过这种东西???(逃 旋转卡壳板子题(听说这个算法有十六种读音??? 我是真的忘了这道题目怎么做了,挂个\(blog\),等我学会了再写题解 我的代码里居然有注释???好像还是 ...

  4. CF336A Vasily the Bear and Triangle 题解

    Content 一个矩形的顶点为 \((0,0)\),其对顶点为 \((x,y)\),现过 \((x,y)\) 作直线,分别交 \(x\) 轴和 \(y\) 轴于 \(A,B\) 两点,使得 \(\t ...

  5. Codechef Not a Triangle题解

    找出一个数组中的三个数,三个数不能组成三角形. 三个数不能组成三角形的条件是:a + b < c 两边和小于第三边. 这个问题属于三个数的组合问题了.暴力法可解,可是时间效率就是O(n*n*n) ...

  6. CF1064A Make a triangle! 题解

    Content 有三条长度分别为 \(a,b,c\) 的线段.你可以在一个单位时间内将一条线段的长度增加 \(1\),试求出能使这三条线段组成一个三角形的最短时间. 数据范围:\(1\leqslant ...

  7. POJ 1927 Area in Triangle 题解

    link Description 给出三角形三边长,给出绳长,问绳在三角形内能围成的最大面积.保证绳长 \(\le\) 三角形周长. Solution 首先我们得知道,三角形的内切圆半径就是三角形面积 ...

  8. 120. Triangle

    题目: Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjace ...

  9. Triangle leetcode java

    题目: Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjace ...

随机推荐

  1. Altium designer18设置原理图尺寸

    1. AD18版本设置原理图尺寸和以前版本不一样,具体是在界面右侧Properties里面的Sheet Sizes.

  2. 你想找的Python资料这里全都有!没有你找不到!史上最全资料合集

    你想找的Python资料这里全都有!没有你找不到!史上最全资料合集 2017年11月15日 13:48:53 技术小百科 阅读数:1931   GitHub 上有一个 Awesome - XXX 系列 ...

  3. 数据库路由中间件MyCat - 背景篇(2)

    此文已由作者张镐薪授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. MyCat的前世今生 如前文所说,Amoeba.Cobar.MyCat等属于同宗一脉.若Amoeba能继续下 ...

  4. 一个体验好的Windows 任务栏缩略图开发心得

    本文来自网易云社区 作者:孙有军 前言: 对于一个追求极致体验的软件来说,利用好系统的每一点优秀的特性,将会大大提高软件的品质. Windows vista以来任务栏缩略图,及Win + TAB的程序 ...

  5. 「日常训练」Duff in the Army (Codeforces Round #326 Div.2 E)

    题意(CodeForces 588E) 给定一棵\(n\)个点的树,给定\(m\)个人(\(m\le n\))在哪个点上的信息,每个点可以有任意个人:然后给\(q\)个询问,每次问\(u\)到\(v\ ...

  6. hdu1312Red and Black(迷宫dfs,一遍)

    Red and Black Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  7. lesson 23 one man's meat is another man's poison

    lesson 23 one man's meat is another man's poison delicacy n. 美味:佳肴: delicious adj. 美味的:可口的 关于虚拟语气: I ...

  8. Java开发工程师(Web方向) - 02.Servlet技术 - 第1章.Servlet

    第1章--Servlet Servlet简介 Servlet应用于? 浏览器发出HTTP请求,服务器接收请求后返回响应给浏览器. 接收请求后到返回响应之间: 服务器将请求对象转交给Servlet容器 ...

  9. Pyhton网络爬虫实例_豆瓣电影排行榜_BeautifulSoup4方法爬取

    -----------------------------------------------------------学无止境------------------------------------- ...

  10. HTMLTestRunner带饼图

    # -*- coding: utf-8 -*- """ A TestRunner for use with the Python unit testing framewo ...