首页 技术 正文
技术 2022年11月11日
0 收藏 999 点赞 2,762 浏览 1859 个字
 //凸包稳定性判断:每条边上是否至少有三点
// POJ 1228 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
#define LL long long
typedef pair<int,int> pii;
const double inf = 0x3f3f3f3f;
const LL MOD =100000000LL;
const int N =;
#define clc(a,b) memset(a,b,sizeof(a))
const double eps = 1e-;
void fre() {freopen("in.txt","r",stdin);}
void freout() {freopen("out.txt","w",stdout);}
inline int read() {int x=,f=;char ch=getchar();while(ch>''||ch<'') {if(ch=='-') f=-; ch=getchar();}while(ch>=''&&ch<='') {x=x*+ch-'';ch=getchar();}return x*f;} int sgn(double x){
if(fabs(x) < eps)return ;
if(x < )return -;
else return ;
} struct Point{
double x,y;
Point(){}
Point(double _x,double _y){
x = _x;y = _y;
}
Point operator -(const Point &b)const{
return Point(x - b.x,y - b.y);
}
double operator ^(const Point &b)const{
return x*b.y - y*b.x;
}
double operator *(const Point &b)const{
return x*b.x + y*b.y;
}
friend bool operator<(const Point &a,const Point &b){
if(fabs(a.y-b.y)<eps) return a.x<b.x;
return a.y<b.y;
}
friend double dis2(Point a){
return a.x*a.x+a.y*a.y;
}
}; double dis(Point a,Point b){
return sqrt(dis2(a-b));
} int mult(Point a,Point b,Point o){
return sgn((a.x-o.x)*(b.y-o.y)-(b.x-o.x)*(a.y-o.y));
}
//返回top个点
int graham(Point p[],int n,Point q[]){
int top=;
sort(p,p+n);
if(n==) return ;
q[]=p[];
if(n==) return ;
q[]=p[];
if(n==) return ;
q[]=p[];
for(int i=;i<n;i++){
while(top&&(mult(p[i],q[top],q[top-])>)) top--;
q[++top]=p[i];
}
int len=top;
q[++top]=p[n-];
for(int i=n-;i>=;i--){
while(top!=len&&(mult(p[i],q[top],q[top-])>)) top--;
q[++top]=p[i];
}
return top;
} // 判断凸包边上是否至少有三点
bool judge(Point p[],int m){
p[m]=p[];
p[m+]=p[];
for(int i=;i<m;i++){
if(mult(p[i-],p[i+],p[i])!=&&mult(p[i],p[i+],p[i+])!=)
return false;
}
return true;
} Point p[];
Point ch[];
int main(){
// fre();
int T;
scanf("%d",&T);
while(T--){
int n;
scanf("%d",&n);
for(int i=;i<n;i++){
double x,y;
scanf("%lf%lf",&x,&y);
p[i]=Point(x,y);
}
int m=graham(p,n,ch);
if(n<) {
puts("NO");
continue;
}
if(judge(ch,m)) puts("YES");
else puts("NO");
}
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,997
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,511
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,356
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,139
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,770
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,848