zoukankan      html  css  js  c++  java
  • HDU 2108 Shape of HDU

                HDU 2108 Shape of HDU

              Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
                    Total Submission(s): 9737    Accepted Submission(s): 4529

    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
    海东集团终于顺利成立了!后面的路,他们会顺顺利利吗? 欲知后事如何,且听下回分解——
     
    思路:根据输入顺序判断是凸多边形还是凹多边形
    (网上搜的题解,求dalao解释)
    #include<iostream>
    #include<cstdlib>
    #include<cstring>
    #include<cstdio>
    #include<cmath>
    using namespace std;
    int x[100], y[100], vis, n;
    
    int main() {
        while(scanf("%d", &n) && n != 0) {
            vis = 0;
            for(int i = 0 ; i < n ; i++)
                scanf("%d%d",&x[i],&y[i]);
            for(int i = 1 ; i <= n ; i++)
                if((x[(i+1)%n]-x[(i%n)])*(y[(i+2)%n]-y[(i+1)%n])-((y[(i+1)%n]-y[i%n])*(x[(i+2)%n]-x[(i+1)%n])) < 0)
                    vis++;
            //注意,并不一定为负或是为正才是凸点.要根据给出点的顺逆时针顺序.
            //如果是顺时针的话,那么大于零的应该是凹点.如果是逆时针则应该是小于零的点.
            //所以,只要存在不全为大于0或者小于零的点就是凹多边形,不用分情况讨论
            if(vis == n || vis == 0) printf("convex
    ");
            else printf("concave
    ");
        }
        return 0;
    }
  • 相关阅读:
    Lerning Entity Framework 6 ------ Defining Relationships
    Lerning Entity Framework 6 ------ Defining the Database Structure
    Lerning Entity Framework 6 ------ Introduction to TPH
    Lerning Entity Framework 6 ------ Introduction to TPT
    Lerning Entity Framework 6 ------ Using a commandInterceptor
    Lerning Entity Framework 6 ------ A demo of using Entity framework with MySql
    C#是否该支持“try/catch/else”语法
    Hadoop学习之旅三:MapReduce
    CLR via C# 摘要二:IL速记
    Java 制表符 " "
  • 原文地址:https://www.cnblogs.com/v-vip/p/8705669.html
Copyright © 2011-2022 走看看