hdu2108Shape of HDU 计算几何

链接:http://acm.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 海东集团终于顺利成立了!后面的路,他们会顺顺利利吗? 欲知后事如何,且听下回分解——

思路:每相邻三个点ABC,AB与BC叉积乘积大于0,则为凸多边形,反之为凹;

代码:

#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<cmath>
#include<algorithm>
#include<string>
#include<string.h>
#include<set>
#include<queue>
#include<stack>
#include<vector>
#include<functional> 
#include<map>
using namespace std;
const int maxn = 200 + 10;
const int INF = (int)1e9;

struct point {
	int x;
	int y;
	point(int x = 0, int y = 0):x(x),y(y){}
};

int n;
point G[maxn];

point operator - (point A, point B) { return point(A.x - B.x, A.y - B.y); }

int Cross(point A, point B, point C) { //叉积
	point v = A - B;
	point u = C - B;
	return (u.x*v.y - u.y*v.x);
}

//或<p>//int Cross(point a , point b , point c)</p><p>//{</p><p>//    return (b.x - a.x)*(c.y - b.y) - (b.y - a.y)*(c.x - b.x);</p><p>//}</p>
 int main()
{
	while (scanf("%d", &n) != EOF && n) {
		for (int i = 1; i <= n; i++)  scanf("%d %d", &G[i].x, &G[i].y);
		int k = 1;
		G[n+1].x = G[1].x;
		G[n+1].y = G[1].y;
		G[0].x = G[n].x;
		G[0].y = G[n].y;
		for (int i = 1; i <= n ; i++) {
			if (Cross(G[i - 1], G[i], G[i + 1]) < 0) {
				k = 0;
				break;
			}	
		}	
		if (k == 1)printf("convex\n");
		else printf("concave\n");
	}
	//system("pause");
	return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值