poj2079Triangle(N点中三点组成三角形面积最大)
根据旋转卡壳的思想,找到当前边的最远点。
确定i,j找到最远的k使 cross(i,j,k)最大,那么i,j+1时只需从k+1开始找即可 。
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 50010
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
struct point
{
int x,y;
point(int x=,int y=):x(x),y(y) {}
} p[N],ch[N];
typedef point pointt;
pointt operator - (point a,point b)
{
return point(a.x-b.x,a.y-b.y);
}
int dcmp(double x)
{
if(fabs(x)<eps) return ;
return x<?-:;
}
double cross(point a,point b)
{
return 1.0*a.x*b.y-1.0*a.y*b.x;
}
double getarea(point a,point b,point c)
{
return fabs(cross(b-a,c-a))/;
}
double mul(point p0,point p1,point p2)
{
return cross(p1-p0,p2-p0);
}
double dis(point a)
{
return sqrt(1.0*a.x*a.x+a.y*a.y);
}
bool cmp(point a,point b)
{
if(dcmp(mul(p[],a,b))==) return dis(a-p[])<dis(b-p[]);
return dcmp(mul(p[],a,b))>;
}
int graham(int n)
{
int i,k=,top;
point tmp;
for(i = ; i< n; i++)
{
if(p[i].y<p[k].y||(p[i].y==p[k].y&&p[i].x<p[k].x))
k = i;
}
if(k!=)
swap(p[],p[k]);
sort(p+,p+n,cmp);
ch[] = p[];
ch[] = p[];
top = ;
for(i = ; i < n; i++)
{
while(top>&&dcmp(mul(ch[top-],ch[top],p[i]))<=)
top--;
ch[++top] = p[i];
}
return top;
}
int main()
{
int n,i,j,k,kk;
while(scanf("%d",&n)!=EOF)
{
if(n==-) break;
for(i = ; i < n; i++)
scanf("%d%d",&p[i].x,&p[i].y);
int top = graham(n);
double maxz=,area;
++top;
ch[top] = ch[];
for(i=; i<top; ++i)
{
j=(i+)%top;
k=(j+)%top;
while(k!=i && getarea(ch[i],ch[j],ch[k])<getarea(ch[i],ch[j],ch[k+]))
k=(k+)%top;
maxz = max(maxz,getarea(ch[i],ch[j],ch[k]));
if(k == i)
continue;
kk=(k+)%top;
while(j!=kk && k!=i)
{
area=getarea(ch[i],ch[j],ch[k]);
if(area>maxz)
area=maxz;
while(k!=i && getarea(ch[i],ch[j],ch[k])<getarea(ch[i],ch[j],ch[k+]))
k=(k+)%top;
maxz = max(maxz,getarea(ch[i],ch[j],ch[k]));
j=(j+)%top;
}
}
printf("%.2f\n",maxz); }return ;
}
poj2079Triangle(N点中三点组成三角形面积最大)的更多相关文章
- C语言:已知三角形三边长求面积
//已知三角形三边长求面积 #include <stdio.h> #include <math.h> int main() { float a,b,c,p,s; int x=0 ...
- iOS开发UI篇—iOS开发中三种简单的动画设置
iOS开发UI篇—iOS开发中三种简单的动画设置 [在ios开发中,动画是廉价的] 一.首尾式动画 代码示例: // beginAnimations表示此后的代码要“参与到”动画中 [UIView b ...
- C#中三种定时器对象的比较
·关于C#中timer类 在C#里关于定时器类就有3个1.定义在System.Windows.Forms里2.定义在System.Threading.Timer类里3.定义在System.Timers ...
- 也用 Log4Net 之将自定义属性记录到文件中 (三)
也用 Log4Net 之将自定义属性记录到文件中 (三) 即解决了将自定义属性记录到数据库之后.一个新的想法冒了出来,自定义属性同样也能记录到文件中吗?答案是肯定的,因为Log4Net既然已经考虑 ...
- 转-Web Service中三种发送接受协议SOAP、http get、http post
原文链接:web服务中三种发送接受协议SOAP/HTTP GET/HTTP POST 一.web服务中三种发送接受协议SOAP/HTTP GET/HTTP POST 在web服务中,有三种可供选择的发 ...
- Flex中的FusionCharts 2D面积图
Flex中的FusionCharts 2D面积图 1.源码 <?xml version="1.0" encoding="utf-8"?> <s ...
- C#中三种定时器对象的比较 【转】
https://www.cnblogs.com/zxtceq/p/5667281.html C#中三种定时器对象的比较 ·关于C#中timer类 在C#里关于定时器类就有3个1.定义在System.W ...
- DB2中三个有关锁变量DB2_EVALUNCOMMITTED,DB2_SKIPDELETED和DB2_SKIPINSERTED的使用
本文主要解释下DB2中三个有关锁变量DB2_EVALUNCOMMITTED,DB2_SKIPDELETED和DB2_SKIPINSERTED的使用 实验环境: DB2 v9.7.0.6 AIX 6.1 ...
- Spring中三种配置Bean的方式
Spring中三种配置Bean的方式分别是: 基于XML的配置方式 基于注解的配置方式 基于Java类的配置方式 一.基于XML的配置 这个很简单,所以如何使用就略掉. 二.基于注解的配置 Sprin ...
随机推荐
- “wsimport -keep ”生成客户端报错“Use of SOAP Encoding is not supported.”
本来想用 “wsimport -keep ” 生成客户端,结果报错“Use of SOAP Encoding is not supported.” 应该是缺jar包, 闲麻烦就发现了百度经验上的 这个 ...
- [HTML]POST方法和GET方法
GET方法: function btn_get_click(){ var httpRequest = new XMLHttpRequest(); httpRequest.onreadystatecha ...
- [ios][opengles]opengles在ios上的透明问题
关于透明,OpenGL/ES 中可以通过 blend (混色) 来简单实现,混色的基本原理就是把要绘制的物体的颜色与屏幕上已经绘制好的颜色以一定比例来混合,最后的颜色看上去就像半透明一样.要使用混合先 ...
- python:正则表达式 re
#re正则的用法:match匹配从开头 search 取一个就回来了,findout取所以匹配的,slit分割 sub替换 #-*- coding:utf8 -*- # Auth:fulimei #r ...
- 关于数据库表中的索引及索引列的CRUD
-- 查询一个数据库表中的索引及索引列use [RuPengWangDB]GOSELECT indexname = a.name , tablename = c. name , indexcolu ...
- Parencodings 分类: POJ 2015-06-28 22:00 7人阅读 评论(0) 收藏
Parencodings Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 22757 Accepted: 13337 De ...
- Hadoop Mac OSX 安装笔记
本次测试安装的机器为Mac Book Pro, 系统为 OS X 10.9.4.Hadoop版本2.4.1. 使用Java版本为Oracle的JDK 1.6.0_65. 1. 下载安装 Hadoop2 ...
- hdu 3398
String Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Subm ...
- Less/Sass编译工具
less中午网站有详细的说明:http://www.1024i.com/demo/less/ 那里我使用的koala 全平台支持,国产.下载地址:http://koala-app.com/inde ...
- Android中直播视频技术探究之---基础知识大纲介绍
一.前言 最近各种视频直播app到处都是,各种霸屏,当然我们也是需要体验的,关于视频直播的软件这里就不介绍了,在不是技术的人来看,直播是一种潮流,是一种娱乐方式,但是作为一个高技术的,我们除了看看,更 ...