QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#346417 | #7730. Convex Checker | tz3528 | WA | 1ms | 3924kb | C++20 | 2.5kb | 2024-03-08 14:53:37 | 2024-03-08 14:53:37 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
//结构定义
//向量、点结构
struct point{
double x,y;
int judge;
/*
判断返回类型
j==0 无解
j==1 有解
*/
};
//以x升序排列,其次以y升序排列
bool sortXupYup(point u,point v){
if(u.x!=v.x) return u.x<v.x;
else return u.y<v.y;
}
//二阶行列式
double det(double a1, double a2, double b1, double b2){return a1*b2-a2*b1;}
//向量运算
//向量、点的加操作
point operator+(point u,point v){return {u.x+v.x,u.y+v.y,1};}
//向量、点的减操作
point operator-(point u,point v){return {u.x-v.x,u.y-v.y,1};}
//向量的乘操作
point operator*(point u,double k){return {u.x*k,u.y*k,1};}
//向量的除操作
point operator/(point u,double k){return {u.x/k,u.y/k,1};}
//叉积运算
double operator^(point u,point v){return u.x*v.y-v.x*u.y;}
//点乘运算
double operator*(point u,point v){return u.x*v.x+u.y*v.y;}
//向量v在向量u的方向
int orderVector(point u,point v){
double p=(u^v);
/*
1表示v在u的逆时针方向
0表示二者同向或反向
-1表示v在u的顺时针方向
*/
if(p>0) return 1;
else if(p==0.0) return 0;
else return -1;
}
/*
Andrew求凸包
调用格式为
point h[n+1];
int size;
maxConvexhull(u,n,h,size);
注意,所有点共线时的特判
若p可为0,则记录了在边界上的所有点,
否则只记录了每条边的端点
看需求而定,若记录边界上的所有点,注意h数组的大小是否足够
*/
void maxConvexhull(point* u,int size,point *h,int &hsize){
/*
采用逆时针求序
其中h为逆时针排序后的最大凸多边形各点组成的数组
*/
std::sort(u+1,u+1+size,sortXupYup);
h[1]=u[1];
//求下凸部分
int top1=1;
for(int i=2;i<=size;i++){
while(top1>1){
int p=orderVector(h[top1]-h[top1-1],u[i]-h[top1]);
if(p==1){
h[++top1]=u[i];
break;
}
else top1--;
}
if(top1==1) h[++top1]=u[i];
}
int top2=1;
for(int i=size-1;i>=1;i--){
while(top2>1){
int p=orderVector(h[top1+top2-1]-h[top1+top2-2],u[i]-h[top1+top2-1]);
if(p==1){
h[++top2+top1-1]=u[i];
break;
}
else top2--;
}
if(top2==1) h[++top2+top1-1]=u[i];
}
hsize=top2+top1-2;
return ;
}
int main(){
int n,m;
cin>>n;
point u[n+10],b[n+10];
for(int i=1;i<=n;i++){
cin>>u[i].x>>u[i].y;
}
maxConvexhull(u,n,b,m);
if(m==n) printf("Yes\n");
else printf("No\n");
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3924kb
input:
3 0 0 1 0 0 1
output:
Yes
result:
ok answer is YES
Test #2:
score: 0
Accepted
time: 0ms
memory: 3864kb
input:
4 0 0 0 1 1 1 1 0
output:
Yes
result:
ok answer is YES
Test #3:
score: 0
Accepted
time: 0ms
memory: 3868kb
input:
4 0 0 0 3 1 2 1 1
output:
Yes
result:
ok answer is YES
Test #4:
score: 0
Accepted
time: 0ms
memory: 3860kb
input:
3 0 0 0 0 0 0
output:
No
result:
ok answer is NO
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 3908kb
input:
5 1 0 4 1 0 1 2 0 3 2
output:
Yes
result:
wrong answer expected NO, found YES