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 ...
随机推荐
- 一个基于和围绕Docker生态环境构建的早期项目列表
https://blog.docker.com/2013/07/docker-projects-from-the-docker-community/
- Linux下资源利用率监测利器—nmon使用
最近接了一个任务,就是测试公司服务器的资源利用率,这样对每种业务平时所占资源有了大体的了解,进而为下一步的虚拟化做准备.找了很多开源的工具,但都不理想,有的安装很复杂,需要联网(而我们的服务器很多都不 ...
- sqlite加密
一直使用sqlite来管理本地的数据,但是Xcode中的SDK中集成的sqlite是免费的,不提供加密模块,但是程序中用到的很多数据,有时候是不想让别人看到,一开始虑修改sqlite的源码,自己重新编 ...
- Meisell-Lehmer算法(统计较大数据里的素数)
http://acm.hdu.edu.cn/showproblem.php?pid=5901 1e11的数据量,这道题用这个算法花了202ms. #include<bits/stdc++.h&g ...
- 收集 关于php的博文
1. 小狼的世界: 浅谈用php实现mvc:http://www.cnblogs.com/cocowool/archive/2009/09/08/1562874.html 关于MVC的定义和解释,可以 ...
- quick-cocos2d-x 接入支付宝(android)(转,待验证)
quick-cocos2d-x 实现在lua里面完成android支付宝的接入 一.支付宝注册是很麻烦的一个过程,本文就不解释了,想了解的去官网看下注册流程.然后下载他们的sdk-WS_SECURE_ ...
- 【转】MYSQL入门学习之十:视图的基本操作
转载地址:http://www.2cto.com/database/201212/176775.html 一.视图的基本介绍 www.2cto.com 视图是虚拟的表.与包含数据 ...
- 【20160924】GOCVHelper 图像增强部分(3)
//顶帽去光差,radius为模板半径 Mat moveLightDiff(Mat src,int radius){ Mat dst; Mat srcclone ...
- JAVA基础知识之IO——对象序列化
对象序列化 Java对象序列化(Serialize)是指将Java对象写入IO流,反序列化(Deserilize)则是从IO流中恢复该Java对象. 对象序列化将程序运行时内存中的对象以字节码的方式保 ...
- register_chrdev、register_chrdev_region以及alloc_chrdev_region之间的区别
register_chrdev:Linux2.6.30之前所用,不用定义cdev:但 如果是register_chrdev 注册的话,这个时候,分配的次设备号,是从0~255,这样子的话,就分配的范围 ...