zoukankan      html  css  js  c++  java
  • Grandpa's Estate POJ

    稳定的凸包满足:在加新点使凸包扩大时,新凸包无法包含原来的所有顶点

    换句话说,一个稳定的凸包的每一条边上都有至少三个顶点

    题目数据比较水,没有所有点共线的特判(非稳定),我也就懒得写了

    //#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=1e3+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;
    }
    
    bool judge(int n){	//判凸包稳定
    	for(int i=1;i<n;i++){
    		if(fabs(xmult(vertex[i],vertex[i+1],vertex[i-1]))>eps
    				&&
    		   fabs(xmult(vertex[i],vertex[i+1],vertex[(i+2)%(n)]))>eps){
    			return 0;
    		}
    	}
    	return 1;
    }
    
    int main(){
    	int T;scanf("%d",&T);
    	while(T--){
    		scanf("%d",&n);
    		for(int i=0;i<n;i++){
    			scanf("%lf%lf",&point[i].x,&point[i].y);
    		}
    
    		tot=Andrew();
    		if(tot<6){
    			printf("NO
    ");continue;
    		}
    		
    		if(judge(tot))printf("YES
    ");else printf("NO
    ");
    	}
    }


  • 相关阅读:
    03_ if 练习 _ little2big
    uva 11275 3D Triangles
    uva 12296 Pieces and Discs
    uvalive 3218 Find the Border
    uvalive 2797 Monster Trap
    uvalive 4992 Jungle Outpost
    uva 2218 Triathlon
    uvalive 3890 Most Distant Point from the Sea
    uvalive 4728 Squares
    uva 10256 The Great Divide
  • 原文地址:https://www.cnblogs.com/Drenight/p/8611243.html
Copyright © 2011-2022 走看看