UVA10078 The Art Gallery凸多边形
Posted 海岛Blog
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UVA10078 The Art Gallery凸多边形相关的知识,希望对你有一定的参考价值。
Century Arts has hundreds of art galleries scattered all around the country and you are hired to write a program that determines whether any of the galleries has a critical point. The galleries are polygonal in shape and a critical point is a point inside that polygon from where the entire gallery is not visible.
For example, in gallery 1 (drawn below) point A is a critical point, but gallery 2 has no critical point at all.
The Century Arts authorities will provide you with the shape of a gallery as a sequence of (x, y) co-ordinates (determined using a suitable origin) of the consecutive corner points of that gallery.
Input
The input file consists of several data blocks. Each data block describes one gallery.
The first line of a data block contains an integer N (3 ≤ N ≤ 50) indicating the number of corner points of the gallery. Each of the next N lines contains two integers giving the (x, y) co-ordinates of a corner point where 0 ≤ x, y ≤ 1000. Starting from the first point given in the input the corner points occur in the same order on the boundary of the gallery as they appear in the input. No three consecutive points are co-linear.
The input file terminates with a value of 0 for N.
Output
For each gallery in the input output the word ‘Yes’ if the gallery contains a critical point, otherwise output the word ‘No’. Each output must be on a separate line.
Sample Input
4
0 0
3 0
3 3
0 3
4
0 0
3 0
1 1
0 3
0
Sample Output
No
Yes
问题链接:UVA10078 The Art Gallery
问题简述:判断多边形是否是凸多边形?
问题分析:简单题,不解释。
程序说明:(略)
参考链接:(略)
题记:(略)
AC的C++语言程序如下:
/* UVA10078 The Art Gallery */
#include <bits/stdc++.h>
using namespace std;
const int N = 50 + 2;
struct Point {
int x, y;
} p[N];
int cross(Point o, Point a, Point b) {
return (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
}
int main()
{
int n;
while (scanf("%d", &n) && n) {
for (int i = 0; i < n; i++)
scanf("%d%d", &p[i].x, &p[i].y);
p[n] = p[0], p[n + 1] = p[1];
int i;
if (cross(p[0], p[1], p[2]) >= 0) {
for (i = 0; i < n; i++)
if (cross(p[i], p[i + 1], p[i + 2]) < 0) break;
} else {
for (i = 0; i < n; i++)
if (cross(p[i], p[i + 1], p[i + 2]) > 0) break;
}
puts(i == n ? "No" : "Yes");
}
return 0;
}
以上是关于UVA10078 The Art Gallery凸多边形的主要内容,如果未能解决你的问题,请参考以下文章
POJ 1279 Art Gallery 半平面交 多边形的核
HDU-4717 The Moving Points(凸函数求极值)