zoukankan      html  css  js  c++  java
  • HDU2108 Shape of HDU(判定凸多边形-模板)

    Shape of HDU

    Problem Description

    话说上回讲到海东集团推选老总的事情,最终的结果是XHD以微弱优势当选,从此以后,“徐队”的称呼逐渐被“徐总”所取代,海东集团(HDU)也算是名副其实了。
    创业是需要地盘的,HDU向钱江肉丝高新技术开发区申请一块用地,很快得到了批复,据说这是因为他们公司研发的“海东牌”老鼠药科技含量很高,预期将占全球一半以上的市场。政府划拨的这块用地是一个多边形,为了描述它,我们用逆时针方向的顶点序列来表示,我们很想了解这块地的基本情况,现在请你编程判断HDU的用地是凸多边形还是凹多边形呢?

    Input

    输入包含多组测试数据,每组数据占2行,首先一行是一个整数n,表示多边形顶点的个数,然后一行是2×n个整数,表示逆时针顺序的n个顶点的坐标(xi,yi),n为0的时候结束输入。

    Output

    对于每个测试实例,如果地块的形状为凸多边形,请输出“convex”,否则输出”concave”,每个实例的输出占一行。

    Sample Input

    4
    0 0 1 0 1 1 0 1
    0
    

    Sample Output

    convex
    
    
    海东集团终于顺利成立了!后面的路,他们会顺顺利利吗?
    欲知后事如何,且听下回分解——
    

    题解

    题意

    逆时针给定点求是否为凸多边形

    思路

    相邻叉积始终为正即可。

    代码

    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<iostream>
    #include<string>
    #include<vector>
    #include<stack>
    #include<bitset>
    #include<cstdlib>
    #include<cmath>
    #include<set>
    #include<list>
    #include<deque>
    #include<map>
    #include<queue>
    using namespace std;
    typedef long long ll;
    const double PI = acos(-1.0);
    const double eps = 1e-6;
    const int INF = 0x3f3f3f3f;
    #define zero(x) (((x)>0?(x):-(x))<eps) //ÅжÏÊÇ·ñΪ0 
    #define _sign(x) ((x)>eps?1:((x)<-eps?2:0)) 
    
    const int MAXN = 1e6+10;
    
    struct point{
    	double x,y;
    	point(double x=0,double y=0):x(x),y(y){}
    }sav[MAXN];
    
    //ÏòÁ¿²æ»ý 
    double xmult (point p1,point p2,point p0){
    	return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
    }
    
    int is_convex(int n,point* p){
    	int i,s[3]={1,1,1};
    	for (i=0;i<n&&s[1]|s[2];i++)
    	s[_sign(xmult(p[(i+1)%n],p[(i+2)%n],p[i]))]=0;
    	return s[1]|s[2];
    } 
    
    int main() {
    	int N;
    	while(~scanf("%d",&N)){
    		if(N==0)	break;
    		memset(sav,0,sizeof(sav));
    		for(int i=0;i<N;i++){
    			scanf("%lf %lf",&sav[i].x,&sav[i].y);
    		}
    		int flag = is_convex(N,sav);
    		if(flag==1)	printf("convex
    ");
    		else	printf("concave
    ");
    	}
        return 0;
    }
    
    
  • 相关阅读:
    SystemVerilog搭建测试平台---第一章:验证导论
    二线制I2C CMOS串行EEPROM续
    二线制I2C CMOS串行EEPROM
    Codeforces 777E:Hanoi Factory(贪心)
    2019HPU-ICPC-Training-1
    Codeforces 777B:Game of Credit Cards(贪心)
    Codeforces 777D:Cloud of Hashtags(暴力,水题)
    Codeforces 777C:Alyona and Spreadsheet(预处理)
    Codeforces 888D: Almost Identity Permutations(错排公式,组合数)
    Codeforces 888E:Maximum Subsequence(枚举,二分)
  • 原文地址:https://www.cnblogs.com/caomingpei/p/9900710.html
Copyright © 2011-2022 走看看