poj - 1228 - Grandpa's Estate
题意:原来一个凸多边形删去一些点后剩n个点,问这个n个点能否确定原来的凸包(1 <= 测试组数t <= 10,1 <= n <= 1000)。
题目链接:http://poj.org/problem?id=1228
——>>初看这题,好别扭,不知道要做什么。。。
其实,是这样的:先求凸包,然后看凸包每一条边所在直线上有多少个点,至少需要3个。
假设一条边的所在直线只有2个点,那么可适当地在这两个点中间加一个或者几个点,使新图形仍是凸包,这时候就不能确定原来的凸包了。
假设一条边的所在直线上有3个以上的点,如果在其中两点间扩展一个点,所形成的图形是凹的,所以不能扩展,即边就确定了。
#include <cstdio>
#include <cmath>
#include <algorithm> using namespace std; const int maxn = 1000 + 10;
const double eps = 1e-10; int dcmp(double x){
if(fabs(x) < eps) return 0;
else return x < 0 ? -1 : 1;
} struct Point{
double x;
double y;
Point(double x = 0, double y = 0):x(x), y(y){}
bool operator < (const Point& e) const{
return x < e.x || (dcmp(x - e.x) == 0 && y < e.y);
}
}p[maxn], q[maxn]; typedef Point Vector; Vector operator + (Point A, Point B){
return Vector(A.x + B.x, A.y + B.y);
} Vector operator - (Point A, Point B){
return Vector(A.x - B.x, A.y - B.y);
} Vector operator * (Point A, double p){
return Vector(A.x * p, A.y * p);
} Vector operator / (Point A, double p){
return Vector(A.x / p, A.y / p);
} double Cross(Vector A, Vector B){
return A.x * B.y - B.x * A.y;
} int ConvexHull(Point *p, int n, Point* ch){ //求凸包
sort(p, p + n);
int m = 0;
for(int i = 0; i < n; i++){
while(m > 1 && Cross(ch[m-1] - ch[m-2], p[i] - ch[m-2]) < 0) m--;
ch[m++] = p[i];
}
int k = m;
for(int i = n-2; i >= 0; i--){
while(m > k && Cross(ch[m-1] - ch[m-2], p[i] - ch[m-2]) < 0) m--;
ch[m++] = p[i];
}
if(n > 1) m--;
return m;
} double ConvexPolygonArea(Point *p, int n){
double area = 0;
for(int i = 1; i < n-1; i++) area += Cross(p[i]-p[0], p[i+1]-p[0]);
return area / 2;
} int main()
{
int t, n;
scanf("%d", &t);
while(t--){
bool ok = 1;
scanf("%d", &n);
for(int i = 0; i < n; i++) scanf("%lf%lf", &p[i].x, &p[i].y);
if(n < 3) ok = 0;
else{
int m = ConvexHull(p, n, q);
if(m < 6) ok = 0;
if(ok) for(int i = 2; i < m; i++){
if(dcmp(Cross(q[i] - q[i-1], q[i] - q[i-2])) != 0){
ok = 0;
break;
}
while(dcmp(Cross(q[i] - q[i-1], q[i] - q[i-2])) == 0) i++;
}
if(dcmp(ConvexPolygonArea(q, m)) == 0) ok = 0;
}
if(ok) puts("YES");
else puts("NO");
}
return 0;
}
poj - 1228 - Grandpa's Estate的更多相关文章
- POJ 1228 - Grandpa's Estate 稳定凸包
稳定凸包问题 要求每条边上至少有三个点,且对凸包上点数为1,2时要特判 巨坑无比,调了很长时间= = //POJ 1228 //稳定凸包问题,等价于每条边上至少有三个点,但对m = 1(点)和m = ...
- POJ 1228 Grandpa's Estate(凸包)
Grandpa's Estate Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11289 Accepted: 3117 ...
- POJ 1228 Grandpa's Estate 凸包 唯一性
LINK 题意:给出一个点集,问能否够构成一个稳定凸包,即加入新点后仍然不变. 思路:对凸包的唯一性判断,对任意边判断是否存在三点及三点以上共线,如果有边不满足条件则NO,注意使用水平序,这样一来共线 ...
- POJ 1228 Grandpa's Estate(凸包唯一性判断)
Description Being the only living descendant of his grandfather, Kamran the Believer inherited all o ...
- POJ 1228 Grandpa's Estate --深入理解凸包
题意: 判断凸包是否稳定. 解法: 稳定凸包每条边上至少有三个点. 这题就在于求凸包的细节了,求凸包有两种算法: 1.基于水平序的Andrew算法 2.基于极角序的Graham算法 两种算法都有一个类 ...
- 简单几何(求凸包点数) POJ 1228 Grandpa's Estate
题目传送门 题意:判断一些点的凸包能否唯一确定 分析:如果凸包边上没有其他点,那么边想象成橡皮筋,可以往外拖动,这不是唯一确定的.还有求凸包的点数<=2的情况一定不能确定. /********* ...
- 【POJ】1228 Grandpa's Estate(凸包)
http://poj.org/problem?id=1228 随便看看就能发现,凸包上的每条边必须满足,有相邻的边和它斜率相同(即共线或凸包上每个点必须一定在三点共线上) 然后愉快敲完凸包+斜率判定, ...
- poj 1228 稳定凸包
Grandpa's Estate Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12337 Accepted: 3451 ...
- poj1228 Grandpa's Estate
地址:http://poj.org/problem?id=1228 题目: Grandpa's Estate Time Limit: 1000MS Memory Limit: 10000K Tot ...
随机推荐
- Nginx 模块开发(1)—— 一个稍稍能说明问题模块开发 Step By Step 过程
1. Nginx 介绍 Nginx是俄罗斯人编写的十分轻量级的HTTP服务器,它的发音为“engine X”, 是一个高性能的HTTP和反向代理服务器,同时也是一个IMAP/POP3/S ...
- win7 安装 redis +php扩展
1:首先下载redis:redis-2.0.2.zip (32 bit),解压. 从下面地址下:http://code.google.com/p/servicestack/wiki/RedisWind ...
- 快速配置 Samba 将 Linux 目录映射为 Windows 驱动器
原文链接 samba client ubuntu redhat ubuntu gui tools 1,列出某个IP地址所提供的共享文件夹 smbclient -L 198.168.0.1 2,在s ...
- 电子科大POJ "敲错键盘"
C-sources: #include<stdio.h> #define N 20 int main() { int i,j; ]={'Q','W','E','R','T','Y','U' ...
- linux动态库加载时搜索路径
摘自http://gotowqj.iteye.com/blog/1926613 对动态库的实际应用还不太熟悉的读者可能曾经遇到过类似“error while loading shared librar ...
- [AS3]as3与JS的交互(AS3调用JS)实例说明
一,AS3 vs JavaScript (1)AS3调用JS 函数: ExternalInterface.(functionName:, arguments): //AS3 Code 属性: 同上,通 ...
- 【稳定婚姻问题】【HDU1435】【Stable Match】
2015/7/1 19:48 题意:给一个带权二分图 求稳定匹配 稳定的意义是对于某2个匹配,比如,( a ---- 1) ,(b----2) , 如果 (a,2)<(a,1) 且(2,a)& ...
- web api (.NET 4.5)
摘自http://blog.csdn.net/fangxing80/article/details/7318289 在刚刚发布的 ASP.NET MVC 4 中,有一个值得注意的新特性——Web Ap ...
- sublime text 2 安装
下载 http://pan.baidu.com/s/1eRemu0y http://jingyan.baidu.com/album/ff4116259b057c12e48237b8.html?pici ...
- java项目使用memcache实现session共享+session基础
本文章主要目的是配置session共享,为了巩固基础,捎带介绍了一些基础知识(网上搜索后觉得最全面的特引过来,节省时间),基础扎实的可以自动忽略. 基础篇: 1.了解java web中的session ...