【POJ 1228】Grandpa's Estate 凸包
找到凸包后暴力枚举边进行$check$,注意凸包是一条线(或者说两条线)的情况要输出$NO$
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 1003
#define read(x) x = getint()
using namespace std;
inline int getint() {
int k = 0, fh = 1; char c = getchar();
for(; c < '0' || c > '9'; c = getchar())
if (c == '-') fh = -1;
for(; c >= '0' && c <= '9'; c = getchar())
k = k * 10 + c - '0';
return k * fh;
}
struct Point {
int x, y;
Point(int _x = 0, int _y = 0) : x(_x), y(_y) {}
};
inline int dcmp(int x) {
return x == 0 ? 0 : (x < 0 ? -1 : 1);
}
Point operator - (Point a, Point b) {
return Point(a.x - b.x, a.y - b.y);
}
bool operator == (Point a, Point b) {
return a.x == b.x && a.y == b.y;
}
inline int Cross(Point a, Point b) {
return a.x * b.y - a.y * b.x;
}
inline int Dot(Point a, Point b) {
return a.x * b.x + a.y * b.y;
}
inline bool jiao(Point d1, Point d2, Point d3, Point d4) {
return (dcmp(Cross(d4 - d3, d1 - d3)) ^ dcmp(Cross(d4 - d3, d2 - d3)) == -2) &&
(dcmp(Cross(d2 - d1, d3 - d1)) ^ dcmp(Cross(d2 - d1, d4 - d1)) == -2);
}
inline bool onin(Point d1, Point d2, Point d3) {
return Cross(d2 - d1, d3 - d1) == 0 && Dot(d2 - d1, d3 - d1) < 0;
} Point a[N], tb[N];
int n, T, top; inline bool cmp(Point d1, Point d2) {
return d1.y == d2.y ? d1.x < d2.x : d1.y < d2.y;
}
inline void mktb() {
top = 2;
tb[1] = a[1];
tb[2] = a[2];
for(int i = 3; i <= n; ++i) {
while (Cross(a[i] - tb[top], tb[top] - tb[top - 1]) >= 0 && top > 1)
--top;
tb[++top] = a[i];
}
int k = top;
tb[++top] = a[n-1];
for(int i = n - 2; i >= 1; --i) {
while (Cross(a[i] - tb[top], tb[top] - tb[top - 1]) >= 0 && top > k)
--top;
tb[++top] = a[i];
}
}
inline bool check(Point d1, Point d2) {
for(int i = 1; i <= n; ++i)
if (onin(a[i], d1, d2))
return 1;
return 0;
}
int main() {
read(T);
while (T--) {
read(n);
for(int i = 1; i <= n; ++i)
read(a[i].x), read(a[i].y);
sort(a + 1, a + n + 1, cmp);
mktb(); bool pd = 1;
for(int i = 2; i <= top; ++i)
if (!check(tb[i], tb[i-1])) {
pd = 0;
break;
} (pd == 0 || top == 3) ? puts("NO") : puts("YES");
}
return 0;
}
这样就可以了
【POJ 1228】Grandpa's Estate 凸包的更多相关文章
- 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 稳定凸包
稳定凸包问题 要求每条边上至少有三个点,且对凸包上点数为1,2时要特判 巨坑无比,调了很长时间= = //POJ 1228 //稳定凸包问题,等价于每条边上至少有三个点,但对m = 1(点)和m = ...
- 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
题意:原来一个凸多边形删去一些点后剩n个点,问这个n个点能否确定原来的凸包(1 <= 测试组数t <= 10,1 <= n <= 1000). 题目链接:http://poj. ...
- 【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 ...
随机推荐
- NOIP2013pj小朋友的数字[DP 最大子段和]
描述 有 n 个小朋友排成一列.每个小朋友手上都有一个数字,这个数字可正可负.规定每个小朋友的特征值等于排在他前面(包括他本人)的小朋友中连续若干个(最少有一个)小朋友手上的数字之和的最大值.作为这些 ...
- MySQL 5.7.x 配置教程
软件环境 操作系统:windows 10 x64 企业版 MySQL:mysql-5.7.11-winx64 MySQL官网下载:http://downloads.mysql.com/archives ...
- u3d_Shader_effects笔记3 half diffuse 和 ramp texture
1.前面的心情 每次写博客,先写心情也好,就当是小日记了吧.现在已经懒到不想动笔和纸来写日记了.近两天公司的活较少,晚上直接回来了,没有留公司.在公司看代码,不做工,就困... 哎,小辉哥家的老房子后 ...
- [转帖]VS选中某个代码报错修补
如题,此问题,出现在xp sp3的情况比较多,至少在我常用的两台电脑上面是这样子的, 完整的安装了VS2010之后,在编写代码的时候,只要用鼠标拖选代码或者双击,选中某个代码,IDE就自动报错 重启 ...
- 如何在CTF中当搅屎棍
论如何在CTF比赛中搅屎 0×00 前言 不能搅屎的CTF不是好CTF,不能搅屎的题目不是好题目. 我很赞成phithon神的一句话,"比赛就是和他人竞争的过程,通过各种手段阻止对手拿分我觉 ...
- 用802.11n 加速,将android手机屏幕投影到win7电脑上
在做Android应用开发的时候,经常需要将已经完成的应用展示给一同开发的小伙伴,然而一直感觉没有找到一种十分方便的办法.特别是看到了开发IOS的小伙伴在做展示的时候的方便.因为Apple既做PC,也 ...
- 58种jQuery模拟CSS3过渡页面切换特效
演示网址 http://www.htmleaf.com/Demo/201503251573.html 点击下载
- jquery无缝间歇向上滚动(间断滚动)
jquery无缝间歇向上滚动 JS部份 $(function(){ var $this = $(".renav"); var scrollTimer; $this.hover(fu ...
- js/jquery判断浏览器的方法小结
在网站前端开发中,浏览器兼容性是前端开发框架要解决的第一个问题,要解决兼容性问题就得首先准确判断出浏览器的类型及其版本,而判断浏览器的版本一般只能通过分析浏览器的userAgent才能知道.今天我们把 ...
- MVC 图片预览
1.页面cshtml <form name="frmInput" id="frmInput" method="post" action ...