首页 > 其他分享 >hdu:Shape of HDU(判断多边形凹凸)

hdu:Shape of HDU(判断多边形凹凸)

时间:2023-01-28 10:56:02浏览次数:35  
标签:yi hdu xi 多边形 int HDU Shape vector

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

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

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


输入样例

4
0 0 1 0 1 1 0 1
0
 

输出样例

convex

以每个顶点为基准与其后两个点判断顺逆时针方向
#include<bits/stdc++.h>
using namespace std;
vector<int> x;
vector<int> y;
bool cro_p(int i,int j,int k)
{
    int ans,x1=x[j]-x[i],x2=x[k]-x[i],y1=y[j]-y[i],y2=y[k]-y[i];
    ans=(x1*y2-x2*y1);
    return ans>0;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int n,xi,yi;
    while(cin>>n,n)
    {
        x.clear();y.clear();//注意清空vector
        for(int i=0;i<n;++i)
        {
            cin>>xi>>yi;
            x.push_back(xi);
            y.push_back(yi);
        }
        bool flag=1;
        for(int i=0;i<n;++i)
        {
            if(!cro_p(i,(i+1)%n,(i+2)%n))
            flag=0;
        }
        if(flag) cout<<"convex"<<'\n';
        else cout<<"concave"<<'\n';
    }
}

 



标签:yi,hdu,xi,多边形,int,HDU,Shape,vector
From: https://www.cnblogs.com/ruoye123456/p/17069827.html

相关文章

  • hdu:"红色病毒"问题(指数型母函数用e^x指数函数来计算)
    ProblemDescription医学界发现的新病毒因其蔓延速度和Internet上传播的”红色病毒”不相上下,被称为”红色病毒”,经研究发现,该病毒及其变种的DNA的一条单链中,胞嘧啶,......
  • hdu:The Balance(母函数)
    ProblemDescriptionNowyouareaskedtomeasureadoseofmedicinewithabalanceandanumberofweights.Certainlyitisnotalwaysachievable.Soyoushou......
  • hdu4135
    求[a,b]中与n互素的数字个数  #include<iostream>#include<algorithm>usingnamespacestd;constintN=200;#defineintlonglonginttot,fac[N];......
  • hdu:Kiki & Little Kiki 2(矩阵快速幂)
    ProblemDescriptionTherearenlightsinacirclenumberedfrom1ton.Theleftoflight1islightn,andtheleftoflightk(1<k<=n)isthelightk-1.A......
  • hdu:Simpsons’ Hidden Talents(kmp)
    ProblemDescriptionHomer:Marge,Ijustfiguredoutawaytodiscoversomeofthetalentsweweren’tawarewehad.Marge:Yeah,whatisit?Homer:Takemefor......
  • hdu:Big Event in HDU(母函数,背包)
    ProblemDescriptionNowadays,weallknowthatComputerCollegeisthebiggestdepartmentinHDU.But,maybeyoudon’tknowthatComputerCollegehadeverbe......
  • hdu:剪花布条(kmp)
    ProblemDescription一块花布条,里面有些图案,另有一块直接可用的小饰条,里面也有一些图案。对于给定的花布条和小饰条,计算一下能从花布条中尽可能剪出几块小饰条来呢?Input......
  • HDU 6157 The Karting
    题目传送门TheKarting思路分析序列上的路径问题,可以转化成起点和终点的匹配问题,dp匹配的权值,记录匹配的标记就可做数据很小,支持\(O(n^3)\)看起来可以直接dp引入......
  • alpha shape algorithm
    一个求轮廓的算法analphavalue(0<α<∞)isaparameterimposingtheprecisionofthefinalboundary.Alargevalue(α->∞)resultsinthealphaboundaryo......
  • hdu:Holding Bin-Laden Captive(母函数,数学)
    ProblemDescriptionWeallknowthatBin-Ladenisanotoriousterrorist,andhehasdisappearedforalongtime.Butrecently,itisreportedthathehidesin......