Grandpa’s Estate POJ - 1228(稳定凸包)
Description
Being the only living descendant of his grandfather, Kamran the Believer inherited all of the grandpa’s belongings. The most valuable one was a piece of convex polygon shaped farm in the grandpa’s birth village. The farm was originally separated from the neighboring farms by a thick rope hooked to some spikes (big nails) placed on the boundary of the polygon. But, when Kamran went to visit his farm, he noticed that the rope and some spikes are missing. Your task is to write a program to help Kamran decide whether the boundary of his farm can be exactly determined only by the remaining spikes.
Input
The first line of the input file contains a single integer t (1 <= t <= 10), the number of test cases, followed by the input data for each test case. The first line of each test case contains an integer n (1 <= n <= 1000) which is the number of remaining spikes. Next, there are n lines, one line per spike, each containing a pair of integers which are x and y coordinates of the spike.
Output
There should be one output line per test case containing YES or NO depending on whether the boundary of the farm can be uniquely determined from the input.
Sample Input
1
6
0 0
1 2
3 4
2 0
2 4
5 0
Sample Output
NO
思路
稳定凸包:一个凸包上每一条边都有至少三个点,这样改凸包不能由另一个凸包减去一个点得来,也即该凸包不能加一个点得到一个更大的凸包。
如下一个不稳定凸包

所以我们只需判断题目所给的点构成的凸包是不是一个稳定凸包即可,即判断每条线是不是都至少有三个点。细节见代码。
AC code
#include<iostream>
#include<string>
#include<map>
#include<algorithm>
#include<memory.h>
#include<math.h>
#include<stdio.h>
#define FAST ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
const int maxn = 2e3 + 5;
const double pi = acos(-1.0);
const double eps = 1e-6;
struct Point {
double x, y;
Point(double x = 0, double y = 0) :x(x), y(y) {
}
};
typedef Point Vector;
Point lst[maxn];
int stk[maxn], top;
Vector operator - (Point A, Point B) {
return Vector(A.x - B.x, A.y - B.y);
}
int sgn(double x) {
if (fabs(x) < eps
稳定凸包判定

本文介绍了一个算法问题——稳定凸包的判定方法。该问题源于一个具体的竞赛题目,要求通过剩余的钉子确定农场边界是否唯一。文章详细解释了稳定凸包的概念,并提供了一段AC代码实现。
最低0.47元/天 解锁文章
1834

被折叠的 条评论
为什么被折叠?



