Grandpa‘s Estate POJ - 1228(稳定凸包--德黑兰赛区)

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

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

_Rikka_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值