hdu 2108 Shape of HDU

http://acm.split.hdu.edu.cn/showproblem.php?pid=2108


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<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<set>
#include<vector>
#include<map>
#define ms(x) memset( (x),0,sizeof(x) );
using namespace std;
typedef long long int ll;
struct node{
    int x,y;
};
int main()
{
    int n;
    while(scanf("%d",&n),n){
        node *a=new node[n+5];
        ms(a);
        for(int i=0;i<n;i++){
            scanf("%d%d",&a[i].x,&a[i].y);
        }
        for(int i=0;i<n;i++){
            double k=1.0*(a[i].y-a[(i+1)%n].y)/(a[i].x-a[(i+1)%n].x);
            double b=a[i].y-k*a[i].x;
            double flag=a[(i+2)%n].y-k*a[(i+2)%n].x-b;
            for(int j=0;j<n;j++){
                if(j==i||j==i+1) continue;
                if(i==n-1){
                    if(j==0) continue;
                }
                if( (flag>0)== ( (a[(j)%n].y-k*a[(j)%n].x-b)>0 )  ){
        
                }else{
                    puts("concave");
                    goto out;
                }
					
            }
        }
        puts("convex");
    out:;
    } 
    return 0;
}



ps
1.凸邊形的點都在一條邊的同一側.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章