hdu 3934&&poj 2079 (凸包+旋转卡壳+求最大三角形面积)
| Time Limit: 3000MS | Memory Limit: 30000K | |
| Total Submissions: 8173 | Accepted: 2423 |
Description
Input
Output
Sample Input
3
3 4
2 6
2 7
5
2 6
3 9
2 0
8 0
6 5
-1
Sample Output
0.50
27.00
Source
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm> using namespace std; #define eps 1e-8
#define MAXX 1000010 typedef struct point
{ double x;
double y;
}point; bool dy(double x,double y){
return x>y+eps; }
bool xy(double x,double y){
return x<y-eps; }
bool dyd(double x,double y){
return x>y-eps; }
bool xyd(double x,double y){
return x<y+eps; }
bool dd(double x,double y){
return fabs(x-y)<eps; } double crossProduct(point a,point b,point c)
{
return (c.x-a.x)*(b.y-a.y)-(c.y-a.y)*(b.x-a.x);
} double dist(point a,point b)
{ return sqrt((b.x-a.x)*(b.x-a.x)+(b.y-a.y)*(b.y-a.y));
} point c[MAXX];
point stk[MAXX];
int top; bool cmp(point a,point b)
{ double len=crossProduct(c[],a,b);
if(dd(len,0.0))
return xy(dist(c[],a),dist(c[],b));
return xy(len,0.0);
} double max(double x,double y)
{ return xy(x,y) ? y : x;
} void Graham(int n)
{ int tmp=;
for(int i=; i<n; i++)
{ if(xy(c[i].x,c[tmp].x) || dd(c[i].x,c[tmp].x) && xy(c[i].y,c[tmp].y))
tmp=i;
}
swap(c[],c[tmp]);
sort(c+,c+n,cmp);
stk[]=c[];
stk[]=c[];
top=;
for(int i=; i<n; i++)
{
while(top>= && xyd(crossProduct(stk[top],stk[top-],c[i]),0.0))
top--;
stk[++top]=c[i];
}
} double rotating(int n)
{
int j=,k=;
double ans=0.0;
stk[n]=stk[];
for(int i=; i<n; i++)
{
while(dy(fabs(crossProduct(stk[(k+)%n],stk[i],stk[j])),fabs(crossProduct(stk[k],stk[i],stk[j]))))
k=(k+)%n;
while(dy(fabs(crossProduct(stk[k],stk[i],stk[(j+)%n])),fabs(crossProduct(stk[k],stk[i],stk[j]))))
j=(j+)%n;
ans=max(ans,fabs(crossProduct(stk[k],stk[i],stk[j])));
}
return ans*0.5;
} int main()
{ int i,j,n;
while(scanf("%d",&n)!=EOF&&n != -)
{ for(i=; i<n; i++)
scanf("%lf%lf",&c[i].x,&c[i].y);
Graham(n);//printf("%d**",top);
double ans=rotating(top+);
printf("%.2lf\n",ans);
}
return ;
}
hdu 3934&&poj 2079 (凸包+旋转卡壳+求最大三角形面积)的更多相关文章
- POJ 2079 Triangle 旋转卡壳求最大三角形
求点集中面积最大的三角形...显然这个三角形在凸包上... 但是旋转卡壳一般都是一个点卡另一个点...这种要求三角形的情况就要枚举底边的两个点 卡另一个点了... 随着底边点的递增, 最大点显然是在以 ...
- bzoj1069: [SCOI2007]最大土地面积 凸包+旋转卡壳求最大四边形面积
在某块平面土地上有N个点,你可以选择其中的任意四个点,将这片土地围起来,当然,你希望这四个点围成的多边形面积最大. 题解:先求出凸包,O(n)枚举旋转卡壳,O(n)枚举另一个点,求最大四边形面积 /* ...
- POJ 2187 凸包+旋转卡壳
思路: 求个凸包 旋转卡壳一下 就求出来最远点对了 注意共线情况 也就是说 凸包如果有一堆点共线保留端点即可 //By SiriusRen #include <cmath> #incl ...
- CodeForces - 682E: Alyona and Triangles(旋转卡壳求最大三角形)
You are given n points with integer coordinates on the plane. Points are given in a way such that th ...
- POJ 2079 Triangle [旋转卡壳]
Triangle Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 9525 Accepted: 2845 Descript ...
- UVA 4728 Squares(凸包+旋转卡壳)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=17267 [思路] 凸包+旋转卡壳 求出凸包,用旋转卡壳算出凸包的直 ...
- Code Chef GEOCHEAT(凸包+旋转卡壳+随机化)
题面 传送门 题解 以下记\(S_i=\{1,2,3,...,i\}\) 我们先用凸包+旋转卡壳求出直径的长度,并记直径的两个端点为\(i,j\)(如果有多条直径随机取两个端点) 因为这个序列被\(r ...
- POJ 2187 Beauty Contest【旋转卡壳求凸包直径】
链接: http://poj.org/problem?id=2187 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...
- poj 2187 Beauty Contest , 旋转卡壳求凸包的直径的平方
旋转卡壳求凸包的直径的平方 板子题 #include<cstdio> #include<vector> #include<cmath> #include<al ...
随机推荐
- Windows下USB磁盘开发系列三:枚举系统中U盘、并获取其设备信息
前面我们介绍了枚举系统中的U盘盘符(见<Windows下USB磁盘开发系列一:枚举系统中U盘的盘符>).以及获取USB设备的信息(见<Windows下USB磁盘开发系列二:枚举系统中 ...
- TI BLE CC2541的SPI主模式
SPI就是用4条线来串行传输数据, 2541只能用模拟的方式用GPIO来做. //*********************************************************** ...
- git 使用详解(5)-- get log 查看提交历史【转】
转自:http://blog.csdn.net/wh_19910525/article/details/7468549 版权声明:本文为博主原创文章,未经博主允许不得转载. 目录(?)[-] 限制 ...
- ARM、Intel、MIPS处理器啥区别?看完全懂了【转】
转自:http://news.mydrivers.com/1/472/472317.htm 安卓支持三类处理器(CPU):ARM.Intel和MIPS.ARM无疑被使用得最为广泛.Intel因为普及于 ...
- linux下异步IO的简单例子【转】
转自:http://blog.chinaunix.net/uid-24567872-id-87677.html 首先,贴一下异步IO中用的的一些结构体,因为平常很少用,整理起来方便查看. aio.h中 ...
- java 调用grads 自动批量生成图片
将 -lbcx 命令 后面的4个参数(gs文件名.参数1.参数2.参数3) 放在单引号里面就可以执行了.
- C# Community Projects
Community Supported C# Drivers See the officially supported MongoDB C# driver mongodb-csharp driver ...
- JavaEE基础(二十)/IO流
1.IO流(IO流概述及其分类) 1.概念 IO流用来处理设备之间的数据传输 Java对数据的操作是通过流的方式 Java用于操作流的类都在IO包中 流按流向分为两种:输入流,输出流. 流按操作类型分 ...
- 教你ECSHOP去版权与标志(新增272版)
前台部分: 1:去掉头部TITLE部分的ECSHOP演示站 Powered by ecshop 前者在后台商店设置 - 商店标题修改 后者打开includes/lib_main.php $page_t ...
- 【转】Firefox快捷键
转载地址: http://www.douban.com/note/140139119/ Ctrl + 数字键来打开第N个标签页这种还要先数完再到键盘上找数字Ctrl + Page Up = 激活左边一 ...