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 ...
随机推荐
- 如何设置虚拟化的centos内、外网络通畅
首先要去确定你的本机(本地物理机)是通过以太网(插网线)上网的,还是通过wifi上网的.这个很重要. 如果是通过以太网去上网,那么虚拟化出来的系统,网络配置应当选择桥接模式. 当然了,也不一定非要用桥 ...
- hdu2099整除的尾数(暴力 省赛)
整除的尾数 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- Cannot assign requested address (connect failed)
压测时,应用服务器报错:Cannot assign requested address (connect failed) 经检查,由于应用服务器,频繁发起http请求,由于每次连接都在很短的时间内结束 ...
- Java开发工程师(Web方向) - 02.Servlet技术 - 期末考试
Servlet课程考试 Servlet课程考试 Servlet课程考试 总分:55分 限定时间:120分钟 进入考试 答案已成功提交!请耐心等待成绩公布 Servlet课程考试: 1(12分) 简单谈 ...
- [CF106C]Buns
面包师Lavrenty打算用馅料做几个面包,然后把它们卖掉. Lavrenty有\(n\)克面团和\(m\)种不同的馅料.馅料种类的下标从\(1到m\),他知道他的第\(i\)种馅料剩下\(a_i\) ...
- java后台接收微信服务号/订阅号消息
1.申请订阅号(适合个人)或者服务号(适合企业) 微信公众平台 2.填写配置 服务器地址: 需要接收消息 的服务端接口地址 令牌:通话识别码,随便写,后端接收时,使用一样的就可以了. 消息加密秘钥 : ...
- 【label】标签组件说明
label标签组件 用来改进表单组件的可用性,使用for属性找到对应的id,或者将控件放在该标签下,当点击时,就会触发对应的控件.目前可以绑定的控件有:<button/>, <che ...
- Python全栈 Web(HTML基础语法)
原文地址: https://yq.aliyun.com/articles/632672 .............................................. ...
- 51单片机实现定时器00H-FFH、定时器000-255
#include< reg51.h> #define uint unsigned int #define uchar unsigned char sfr P0M0 = 0x94; sfr ...
- Stunnel客户端安装和配置
声明:本文并非原创,转自华为云帮助中心的分布式缓存服务(DCS)的用户指南. 本文以公网访问华为云分布式缓存服务的Redis缓存为示例,介绍Stunnel客户端在各操作系统下的安装和配置. Stunn ...