POJ 2079 Triangle(凸包+旋转卡壳,求最大三角形面积)
Time Limit: 3000MS | Memory Limit: 30000K | |
Total Submissions: 7625 | Accepted: 2234 |
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 <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
using namespace std; struct Point
{
int x,y;
Point(int _x = , int _y = )
{
x = _x;
y = _y;
}
Point operator -(const Point &b)const
{
return Point(x - b.x, y - b.y);
}
int operator ^(const Point &b)const
{
return x*b.y - y*b.x;
}
int operator *(const Point &b)const
{
return x*b.x + y*b.y;
}
void input()
{
scanf("%d%d",&x,&y);
}
};
int dist2(Point a,Point b)
{
return (a-b)*(a-b);
}
const int MAXN = ;
Point list[MAXN];
int Stack[MAXN],top;
bool _cmp(Point p1,Point p2)
{
int tmp = (p1-list[])^(p2-list[]);
if(tmp > )return true;
else if(tmp == && dist2(p1,list[]) <= dist2(p2,list[]))
return true;
else return false;
}
void Graham(int n)
{
Point p0;
int k = ;
p0 = list[];
for(int i = ;i < n;i++)
if(p0.y > list[i].y || (p0.y == list[i].y && p0.x > list[i].x))
{
p0 = list[i];
k = i;
}
swap(list[],list[k]);
sort(list+,list+n,_cmp);
if(n == )
{
top = ;
Stack[] = ;
return;
}
if(n == )
{
top = ;
Stack[] = ;
Stack[] = ;
return;
}
Stack[] = ;
Stack[] = ;
top = ;
for(int i = ;i < n;i++)
{
while(top > && ((list[Stack[top-]]-list[Stack[top-]])^(list[i]-list[Stack[top-]])) <= )
top--;
Stack[top++] = i;
}
}
//旋转卡壳,求两点间距离平方的最大值
int rotating_calipers(Point p[],int n)
{
int ans = ;
Point v;
int cur = ;
for(int i = ;i < n;i++)
{
int j = (i+)%n;
int k = (j+)%n;
while(j != i && k != i)
{
ans = max(ans,abs((p[j]-p[i])^(p[k]-p[i])) );
while( ( (p[i]-p[j])^(p[(k+)%n]-p[k]) ) < )
k = (k+)%n;
j = (j+)%n;
}
}
return ans;
}
Point p[MAXN];
int main()
{
int n;
while(scanf("%d",&n) == )
{
if(n == -)break;
for(int i = ;i < n;i++)
list[i].input();
Graham(n);
for(int i = ;i < top;i++)
p[i] = list[Stack[i]];
int ans = rotating_calipers(p,top);
printf("%.2lf\n",ans/2.0);
}
return ;
}
POJ 2079 Triangle(凸包+旋转卡壳,求最大三角形面积)的更多相关文章
- hdu 3934&&poj 2079 (凸包+旋转卡壳+求最大三角形面积)
链接:http://poj.org/problem?id=2079 Triangle Time Limit: 3000MS Memory Limit: 30000K Total Submissio ...
- poj 2079 Triangle,旋转卡壳求点集的最大三角形
给出一个点集,求顶点在点集中的最大的三角形面积. 我们知道这三角形的三个点肯定在凸包上,我们求出凸包之后不能枚举,由于题目n比較大,枚举的话要O(n^3)的数量级,所以採用旋转卡壳的做法: 首先枚举三 ...
- poj 2079 Triangle(旋转卡壳)
Triangle Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 8917 Accepted: 2650 Descript ...
- bzoj1069: [SCOI2007]最大土地面积 凸包+旋转卡壳求最大四边形面积
在某块平面土地上有N个点,你可以选择其中的任意四个点,将这片土地围起来,当然,你希望这四个点围成的多边形面积最大. 题解:先求出凸包,O(n)枚举旋转卡壳,O(n)枚举另一个点,求最大四边形面积 /* ...
- POJ 2079 Triangle 旋转卡壳求最大三角形
求点集中面积最大的三角形...显然这个三角形在凸包上... 但是旋转卡壳一般都是一个点卡另一个点...这种要求三角形的情况就要枚举底边的两个点 卡另一个点了... 随着底边点的递增, 最大点显然是在以 ...
- poj 2187 Beauty Contest , 旋转卡壳求凸包的直径的平方
旋转卡壳求凸包的直径的平方 板子题 #include<cstdio> #include<vector> #include<cmath> #include<al ...
- 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 ...
- 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 2079 Triangle (二维凸包旋转卡壳)
Triangle Time Limit: 3000MS Memory Limit: 30000KB 64bit IO Format: %I64d & %I64u Submit Stat ...
随机推荐
- Laravel 项目上线的一些注意事项
1.应用生产环境 在 .env 文件里设置 APP_ENV=production 2.关闭调试模式 在 .env 文件中设置 APP_DEBUG = false 3.生成 APP_KEY 使用 Art ...
- 安全测试===黑客攻击常用cmd命令大全
黑客常用命令大全net user heibai lovechina /add 加一个heibai的用户密码为lovechina net localgroup Administrators heibai ...
- delphi2006语言新特性:Record类型高级用法
delphi语言在传统的Records类型的基础上增加了许多像类一样的高级功能,如:Records可以有属性和方法(包括构造constructors),类属性,类方法,类静态字段和内嵌类型.下面这个示 ...
- VPS速度测试(4):上传下载速度、服务器带宽、Ping响应时间
1.VPS的速度好坏经常是我们选择某一个VPS商家的重要参考指标,对于国外的VPS主机我们可以执行以下命令来测试VPS入口带宽是多少. wget https://cachefly.cachefly.n ...
- [hadoop][会装]HBase集群安装--基于hadoop ha模式
可以参考部署HBase系统(分布式部署) 和基于无HA模式的hadoop下部署相比,主要是修改hbase-site .xml文件,修改如下参数即可: <property> <name ...
- [New learn]动画-基于UIView
原文:https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/ViewPG_iPhoneOS/Ani ...
- ORACLE导入Excel数据
首先建好一个和Excel表字段对应字段的表,然后 select t.* from 表名 t for update; 点击这个锁子,打开它 粘贴,然后 再提交事务即可
- FineReport——JS二次开发(局部刷新)
在FR中,可以通过在form表单设置多个报表模板,然后通过对某一模板刷新实现局部刷新的功能,在cpt模板中,由于只存在一个模板,所以无法实现局部刷新. 其实,最好的局部刷新办法是自定义一个页面,然后添 ...
- [ Python ] 基本数据类型及属性(下篇)
1. 基本数据类型 (1) list 列表 (2) tuple 元组 (3) dict 字典 (4) set 集合 2. list 列表方法 Python 内置的一种数据类型, ...
- Objective-C字符串处理的函数
Objective-C字符串处理的函数 NSLog(@"字符串处理"); //获得字符串长度 NSString* str1=@"MAC OS Pro"; NSL ...