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

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

随着底边点的递增, 最大点显然是在以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. ACM训练联盟周赛(第一场)

    B:Zeratul与Xor 题目描述 Xor(按位异或),对应C++中的“^”运算符. Zeratul给出了一个数列A[n](n≤105),要做q(q≤105)组动作,这些动作包括: 1  a:数列中 ...

  2. codeforces 495D Sonya and Matrix

    Since Sonya has just learned the basics of matrices, she decided to play with them a little bit. Son ...

  3. Surfaces

    For Developers‎ > ‎Design Documents‎ > ‎Chromium Graphics // Chrome GPU‎ > ‎ Surfaces Goals ...

  4. [UVa11549]Calculator Conundrum

    题目大意:有一个只能显示n位数字的计算器,当溢出时只显示最高的n位. 输入k,要你不断平方,问你计算器显示的最大数是多少. 解题思路:这题的示数肯定会循环,那么我们关键就是找什么时候循环了. 可以用F ...

  5. HDU 4917 Permutation 拓扑排序的计数

    题意: 一个有n个数的排列,给你一些位置上数字的大小关系.求合法的排列有多少种. 思路: 数字的大小关系可以看做是一条有向边,这样以每个位置当点,就可以把整个排列当做一张有向图.而且题目保证有解,所以 ...

  6. 【Henu ACM Round#20 C】 Eevee

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 处理处所有的字符串可能的样子. 存在map里面就好. [代码] #include <bits/stdc++.h> usi ...

  7. What is x86 Conforming Code Segment?

    SRC=Microprocessor Based Systems SRC=Computer Architecture: A Quantitative Approach

  8. jfinal 后台文件上传(结合上一篇(h5 图片回显))

    前端用了jquery.form.js插件异步提交表单 $("#imgForm").ajaxSubmit();//户主头像 /** * * @description 上传户主头像 * ...

  9. 巧用FPGA中资源

    随着FPGA的广泛应用,所含的资源也越来越丰富,从基本的逻辑单元.DSP资源和RAM块,甚至CPU硬核都能集成在一块芯片中.在做FPGA设计时,如果针对FPGA中资源进行HDL代码编写,对设计的资源利 ...

  10. HMACSHA256 Class

    https://msdn.microsoft.com/en-us/library/system.security.cryptography.hmacsha256(v=vs.110).aspx Comp ...