zoukankan      html  css  js  c++  java
  • 最大三角形 HDU

    整理了一下旋转卡壳的模板,把接口统一了一下

    //#include<bits/stdc++.h>  
    //#pragma comment(linker, "/STACK:1024000000,1024000000")   
    #include<stdio.h>  
    #include<algorithm>  
    #include<queue>  
    #include<string.h>  
    #include<iostream>  
    #include<math.h>  
    #include<set>  
    #include<map>  
    #include<vector>  
    #include<iomanip>  
    using namespace std;  
      
    const double pi=acos(-1.0);  
    #define ll long long  
    #define pb push_back
    
    #define sqr(a) ((a)*(a))
    #define dis(a,b) sqrt(sqr(a.x-b.x)+sqr(a.y-b.y))
    
    const double eps=1e-6;
    const int maxn=5e4+56;
    const int inf=0x3f3f3f3f;
    
    int n;
    int tot;	//凸包上点数
    
    struct Point{
    	double x,y;
    	Point(){}
    	Point(double x,double y):x(x),y(y){}
    }point[maxn],vertex[maxn];
    
    bool cmp(Point a,Point b){
    	return(a.y<b.y||(a.y== b.y && a.x<b.x));
    }
    
    double xmult(Point p1,Point p2,Point p3){	//p3p1,p3p2的夹角测试
    	return ( (p1.x-p3.x)*(p2.y-p3.y)-(p1.y-p3.y)*(p2.x-p3.x) );
    }		//正表示p1在p2的顺时针方向
    
    int Andrew(){		//返回凸包顶点数
    	sort(point,point+n,cmp);
    	int top=1;
    	vertex[0]=point[0];vertex[1]=point[1];
    	for(int i=2;i<n;i++){ 
    		while(top && xmult(point[i],vertex[top],vertex[top-1])>eps)top--;
    		vertex[++top]=point[i];
    	}
    	int len=top;
    	vertex[++top]=point[n-2];
    	for(int i=n-3;i>=0;i--){
    		while(top!=len && xmult(point[i],vertex[top],vertex[top-1])>eps)top--;
    		vertex[++top]=point[i];
    	}
    	return top;
    }
    
    double rotating_calipers_r(int n){	//返回最大直径
    	int q=1;double ans=0;
    	vertex[n]=vertex[0];
    	for(int p=0;p<n;p++){
    		while(xmult(vertex[p+1],vertex[q+1],vertex[p])>xmult(vertex[p+1],vertex[q],vertex[p]))q=(q+1)%n;
    		ans=max(ans,max(dis(vertex[p],vertex[q]),dis(vertex[p+1],vertex[q+1])));
    		//更新方法是为了处理p,p+1 // q,q+1这种平行状况
    	}
    	return ans;
    }
    double rotating_calipers_s(int m){	//最大三角形面积
    	if(m==1||m==2)return 0;
    	double ans=0;
    	for(int i=0;i<m;i++){
    		int q=1;
    		for(int j=i+1;j<m;j++){
    			while(xmult(vertex[j],vertex[q+1],vertex[i])>xmult(vertex[j],vertex[q],vertex[i]))q=(q+1)%m;
    			ans=max(ans,xmult(vertex[i],vertex[j],vertex[q]));
    		}
    	}
    	return ans/2.0;
    }
    
    int main(){
    	while(~scanf("%d",&n)){
    		for(int i=0;i<n;i++){
    			scanf("%lf%lf",&point[i].x,&point[i].y);
    		}
    		int m=Andrew();
    		printf("%.2lf
    ",rotating_calipers_s(m));
    	}
    }


  • 相关阅读:
    volumetric rendering ---fog/ light/cloud
    strand based hair rendering
    一个相当复杂的延迟管线
    wenti
    ubunt tmux X Error of failed request
    Python编程练习题
    ubuntu15.04 安装 pylab失败,先记下来,漫漫看
    翻译:打造基于Sublime Text 3的全能python开发环境
    关于web2py外网访问,图形界面不显示等问题的解决办法
    yii2中gii外网访问的配置方法
  • 原文地址:https://www.cnblogs.com/Drenight/p/8611241.html
Copyright © 2011-2022 走看看