POJ1228:Grandpa's Estate——题解
http://poj.org/problem?id=1228
题目大意:给一个凸包,问是否为稳定凸包。
————————————————————————
稳定凸包的概念为:我任意添加一个点都不能使这个凸包得到扩充,这样的凸包为稳定凸包。
我们求完凸包后枚举边然后枚举有多少点在上面即可。
(网上的程序真的大部分是错的……)
#include<cstdio>
#include<queue>
#include<cctype>
#include<cstring>
#include<stack>
#include<cmath>
#include<algorithm>
using namespace std;
const int N=;
struct point{
int x;
int y;
}p[N],q[N];
int n,per[N],l;
inline point getmag(point a,point b){
point s;
s.x=b.x-a.x;s.y=b.y-a.y;
return s;
}
inline int multiX(point a,point b){
return a.x*b.y-b.x*a.y;
}
inline int dis(point a,point b){
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
inline bool cmp(int u,int v){
int det=multiX(getmag(p[],p[u]),getmag(p[],p[v]));
if(det!=)return det>;
return dis(p[],p[u])<dis(p[],p[v]);
}
void graham(){
int id=;
for(int i=;i<=n;i++){
if(p[i].x<p[id].x||(p[i].x==p[id].x&&p[i].y<p[id].y))id=i;
}
if(id!=)swap(p[],p[id]);
for(int i=;i<=n;i++)per[i]=i;
sort(per+,per+n+,cmp);
l=;
q[++l]=p[];
for(int i=;i<=n;i++){
int j=per[i];
while(l>=&&multiX(getmag(q[l-],p[j]),getmag(q[l-],q[l]))>=){
l--;
}
q[++l]=p[j];
}
return;
}
bool judge(){
for(int i=;i<=l;i++){
int sum=;
for(int j=;j<=n;j++){
if(multiX(getmag(q[i],p[j]),getmag(p[j],q[i%l+]))==)sum++;
}
if(sum<)return ;
}
bool flag=;
for(int i=;i<=l&&!flag;i++){
if(multiX(getmag(q[i-],q[i]),getmag(q[i],q[i%l+]))!=)flag=;
}
return flag;
}
int main(){
int t;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(int i=;i<=n;i++)scanf("%d%d",&p[i].x,&p[i].y);
graham();
if(judge())puts("YES");
else puts("NO");
}
return ;
}
POJ1228:Grandpa's Estate——题解的更多相关文章
- poj1228 Grandpa's Estate
地址:http://poj.org/problem?id=1228 题目: Grandpa's Estate Time Limit: 1000MS Memory Limit: 10000K Tot ...
- POJ1228 Grandpa's Estate 稳定凸包
POJ1228 转自http://www.cnblogs.com/xdruid/archive/2012/06/20/2555536.html 这道题算是很好的一道凸包的题吧,做完后会加深对凸包的 ...
- POJ 1228 Grandpa's Estate(凸包)
Grandpa's Estate Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11289 Accepted: 3117 ...
- POJ1228:Grandpa's Estate(给定一些点,问是否可以确定一个凸包)
Being the only living descendant of his grandfather, Kamran the Believer inherited all of the grandp ...
- 【POJ】1228 Grandpa's Estate(凸包)
http://poj.org/problem?id=1228 随便看看就能发现,凸包上的每条边必须满足,有相邻的边和它斜率相同(即共线或凸包上每个点必须一定在三点共线上) 然后愉快敲完凸包+斜率判定, ...
- Grandpa's Estate - POJ 1228(稳定凸包)
刚开始看这个题目不知道是什么东东,后面看了大神的题解才知道是稳定凸包问题,什么是稳定凸包呢?所谓稳定就是判断能不能在原有凸包上加点,得到一个更大的凸包,并且这个凸包包含原有凸包上的所有点.知道了这个东 ...
- 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 凸包
找到凸包后暴力枚举边进行$check$,注意凸包是一条线(或者说两条线)的情况要输出$NO$ #include<cmath> #include<cstdio> #include ...
随机推荐
- hive自定义函数——hive streaming
Hadoop Streaming提供了一个便于进行MapReduce编程的工具包,使用它可以基于一些可执行命令.脚本语言或其他编程语言来实现Mapper和 Reducer,Streaming方式是基于 ...
- C#监听锁屏代码
今天,偶然间在技术群看有人问,怎么监听锁屏. 在此处记录一下 public class Constrctor { public Constrctor() { SystemEvents.SessionS ...
- 使用 adb 命令一次性为多个设备安装 apk
使用 adb 命令一次性为多个设备安装 apk 原创 2016年07月15日 10:40:53 3154 命令简介 adb install [-lrtsdg] (file) 把包文件推送到设备上并安装 ...
- 【radio-group、radio】 单选项组件说明
radio-group组件是包裹radio组件的容器 原型: <radio-group bindchange="[EventHandle]"> <radio .. ...
- 【递归入门】组合的输出:dfs
题目描述 排列与组合是常用的数学方法,其中组合就是从n个元素中抽出r个元素(不分顺序且r < = n),我们可以简单地将n个元素理解为自然数1,2,…,n,从中任取r个数. 现要求你不用递归的方 ...
- hibernate提示Unknown entity: :xxx
错误提示: org.hibernate.MappingException: Unknown entity: org.dao.po.Role at org.hibernate.internal.Sess ...
- halcon基础应用和方法经验分享
halcon基础应用和方法经验分享 一.Halcon软件 的安装 安装一直点下一步就好了,这个过程很简单,就不讲了 二.Halcon软件license安装 Halcon是商业视觉软件,是需要收费的,但 ...
- openstack如何整合vmare最佳方案
OpenStack中国社区编者按:通过多年的发展,VMWare在虚拟化市场处于领军地位,很多企业部署了VMWare虚拟化方案,随着OpenStack云计算平台的快速崛起,很多企业都面临一个问题:能否. ...
- 在 CentOS 下手工安装 Docker v1.1x
Docker在 centos 6.x 下面默认最新的版本是1.7, 然而这个并不符合我的实际需求, 尤其我需要 docker-compose 来作为编配工具部署swarm, 所以我只有手工安装了. 首 ...
- URAL 1664 Pipeline Transportation(平面图最大流)
Description An oligarch Vovan, as many other oligarchs, transports oil from West Cuckooland to East ...