求点集中面积最大的三角形...显然这个三角形在凸包上...

但是旋转卡壳一般都是一个点卡另一个点...这种要求三角形的情况就要枚举底边的两个点 卡另一个点了...

随着底边点的递增, 最大点显然是在以l(i,j)为底边进行卡壳旋转

但分析了一下这种卡壳的复杂度到了O(n^2) 感觉不太靠谱...不知道有没有更强的方法...我感觉两个点卡的时候都是凸函数...不是很好卡的样子...如果我想到了我再更新这贴...

/********************* Template ************************/
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std; #define EPS 1e-8
#define MAXN 100005
#define MOD (int)1e9+7
#define PI acos(-1.0)
#define INF ((1LL)<<50)
#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) < (b) ? (a) : (b))
#define max3(a,b,c) (max(max(a,b),c))
#define min3(a,b,c) (min(min(a,b),c))
#define BUG cout<<"BUG! "<<endl
#define LINE cout<<"------------------"<<endl
#define L(t) (t << 1)
#define R(t) (t << 1 | 1)
#define Mid(a,b) ((a + b) >> 1)
#define lowbit(a) (a & -a)
#define FIN freopen("in.txt","r",stdin)
#pragma comment (linker,"/STACK:102400000,102400000") // typedef long long LL;
// typedef unsigned long long ULL;
// typedef __int64 LL;
// typedef unisigned __int64 ULL;
// int gcd(int a,int b){ return b?gcd(b,a%b):a; }
// int lcm(int a,int b){ return a*b/gcd(a,b); } /********************* F ************************/
struct POINT{
double x,y;
POINT(double _x = , double _y = ):x(_x),y(_y){};
void show(){
cout<<x<<" "<<y<<endl;
}
};
POINT p[MAXN],s[MAXN];
double dist(POINT p1,POINT p2){
return((p1.x-p2.x) * (p1.x-p2.x) + (p1.y-p2.y) * (p1.y-p2.y));
}
double multiply(POINT sp,POINT ep,POINT op){
return (sp.x-op.x) * (ep.y-op.y) - (ep.x-op.x) * (sp.y-op.y);
}
bool ptcmp(POINT a,POINT b){ // 极角排序cmp p[]为全局变量
if(multiply(a,b,p[]) == ) return dist(p[],a) < dist(p[],b);
return (multiply(a,b,p[]) > );
}
int Graham_scan(POINT p[],POINT s[],int n){ // 返回凸包点的个数(修改版处理共线,无凸包)
int i,k = ,top = ;
for(i = ; i < n ; i++) // 取y最小且x最小的点为凸包起点
if((p[i].y < p[k].y) || ((p[i].y == p[k].y) && (p[i].x < p[k].x)))
k = i;
swap(p[],p[k]); // 起点设置为p[0]
if(n == ) { // 只有两个点不构成凸包的特判
s[] = p[];
s[] = p[];
return ;
}
sort(p+,p+n,ptcmp); // 极角排序
for(i = ; i < ; i++)
s[i] = p[i]; // 前三个点入栈
if(n == && multiply(s[],s[],s[]) != ) return ;// 解决三个点且不共线的bug...
while(multiply(s[],s[top],s[top-]) == && i < n){ // 前三个点的共线特判
s[top-] = s[top];
s[top] = p[i++];
}
if(i == n){ //所有点都共线的特判
s[] = s[top];
return ;
}
for(; i < n ; i++){
while(multiply(p[i],s[top],s[top-]) >= )
top--;
s[++top] = p[i];
}
return top + ;
}
double Triangle_area(POINT a,POINT b,POINT c){
return fabs(multiply(a,b,c)/);
}
double Rotation_Calipers(int len){ //旋转卡壳求凸包最大三角形
double ans = ;
for(int i = ; i < len ; i++){
int j = (i + ) % len;
int k = (j + ) % len;
while(j != i && k != i){
ans = max(ans,Triangle_area(s[i],s[j],s[k]));
while(Triangle_area(s[i],s[j],s[(k+)%len]) > Triangle_area(s[i],s[j],s[k]))
k = (k + ) % len;
j = (j + ) % len;
}
}
return ans;
}
int main()
{
//freopen("in.txt","r",stdin);
//freopen("ou.txt","w",stdout);
int n;
while(~scanf("%d",&n)){
if(n == -) break;
for(int i = ; i < n ; i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
int len = Graham_scan(p,s,n);
double ans = Rotation_Calipers(len);
printf("%.2lf\n",ans);
}
return ;
}

POJ 2079 Triangle 旋转卡壳求最大三角形的更多相关文章

  1. POJ 2079 Triangle [旋转卡壳]

    Triangle Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 9525   Accepted: 2845 Descript ...

  2. hdu 3934&&poj 2079 (凸包+旋转卡壳+求最大三角形面积)

    链接:http://poj.org/problem?id=2079 Triangle Time Limit: 3000MS   Memory Limit: 30000K Total Submissio ...

  3. 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 ...

  4. poj 2187 Beauty Contest , 旋转卡壳求凸包的直径的平方

    旋转卡壳求凸包的直径的平方 板子题 #include<cstdio> #include<vector> #include<cmath> #include<al ...

  5. UVa 1453 - Squares 旋转卡壳求凸包直径

    旋转卡壳求凸包直径. 参考:http://www.cppblog.com/staryjy/archive/2010/09/25/101412.html #include <cstdio> ...

  6. [hdu5251]矩形面积 旋转卡壳求最小矩形覆盖

    旋转卡壳求最小矩形覆盖的模板题. 因为最小矩形必定与凸包的一条边平行,则枚举凸包的边,通过旋转卡壳的思想去找到其他3个点,构成矩形,求出最小面积即可. #include<cstdio> # ...

  7. POJ2187 旋转卡壳 求最长直径

    给定平面上的一些散点集,求最远两点距离的平方值. 题解: 旋转卡壳求出凸包,然后根据单调性,求出最远两点的最大距离 #pragma GCC optimize(2) #pragma G++ optimi ...

  8. POJ 2079 Triangle(凸包+旋转卡壳,求最大三角形面积)

    Triangle Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 7625   Accepted: 2234 Descript ...

  9. poj 2079 Triangle,旋转卡壳求点集的最大三角形

    给出一个点集,求顶点在点集中的最大的三角形面积. 我们知道这三角形的三个点肯定在凸包上,我们求出凸包之后不能枚举,由于题目n比較大,枚举的话要O(n^3)的数量级,所以採用旋转卡壳的做法: 首先枚举三 ...

随机推荐

  1. php基础:implode()函数 和exlplode函数

    1implode() 函数返回一个由数组元素组合成的字符串. 注释:implode() 函数接受两种参数顺序.但是由于历史原因,explode() 是不行的,您必须保证 separator 参数在 s ...

  2. 修改route.php文件对ThinkPHP快速注册路由

    THINKPHP快速注册路由方式可以用 return[ "test"=>"index/index/demo", 'getid/:id'=>'inde ...

  3. luoguP1401 城市(二分答案+最大流)

    题意 N(2<=n<=200)个城市,M(1<=m<=40000)条无向边,你要找T(1<=T<=200)条从城市1到城市N的路,使得最长的边的长度最小,边不能重复 ...

  4. Linux权限管理(用户、组、文件管理)

    一. Linux上的文件管理类命令都有哪些,其常用的使用方法及其相关示例演示. 1. 文件查看类命令cat,tac, head, tail, more, less, ls ,file: -ls : l ...

  5. 【Henu ACM Round#19 C】 Developing Skills

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 优先把不是10的倍数的变成10的倍数. (优先%10比较大的数字增加 如果k还有剩余. 剩下的数字都是10的倍数了. 那么先加哪一个 ...

  6. 解决Python 插查 MySQL 时中文乱码问题

    首先找到这里的解决方法, count = cursor.fetchall() for i in count: idc_a = i[0] if isinstance(idc_a, unicode): i ...

  7. 关于post请求“CAUTION: Provisional headers are shown”【转】

    在POST请求中偶尔会出现"CAUTION: Provisional headers are shown" 这个警告的意思是说:请求的资源可能会被(扩展/或其它什么机制)屏蔽掉. ...

  8. HTML <button> 标签

    HTML <button> 标签 目标 实现点击button跳转到一个新的界面 参考文档 实例 以下代码标记一个按钮: <button type="button" ...

  9. gym 100735I

    Description standard input/outputStatements You are given three numbers. Is there a way to replace v ...

  10. eq3

    然而一旦美国经济进入持续复苏,美联储必将逐步退出量化宽松和逐渐收紧银根,美国联邦基金利率和银行同业间拆借利率将会上升.这将使美元升值,并使部分套利交易平仓.而一旦美元企稳走强,国债利率上扬,大宗商品价 ...