QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#406383 | #7730. Convex Checker | RainningLove | WA | 55ms | 37784kb | C++20 | 3.0kb | 2024-05-07 10:53:50 | 2024-05-07 10:53:50 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const long double pi=acosl(-1);
struct Point {
long long x,y;
int id;
long double a2;
friend bool operator<(Point a,Point b) {
if(a.x==b.x)return a.y<b.y;
return a.x<b.x;
}
Point(long long x,long long y,int id) {
this->x=x;
this->y=y;
this->a2=atan2l(this->y,this->x);
this->id=id;
}
};
struct Line {
long double A,B,C;
Line(Point a,Point b) {
this->A = b.y-a.y;
this->B = a.x-b.x;
this->C = a.y*b.x - a.x*b.y;
}
int contains(Point x) {
if(A*x.x + B*x.y+C==0) return 1;
return 0;
}
};
struct Vector {
long double x,y;
Vector(Point a,Point b) {
this->x=b.x-a.x;
this->y=b.y-a.y;
}
};
int n;
vector<Point> a;
vector<Point> getConvex(vector<Point> a) {
vector<Point> convex;
int id=0;
for(int i=0;i<n;i++) {
if(a[id].y>a[i].y ||(a[id].y==a[i].y&&a[id].x>a[i].x))id=i;
}
swap(a[id],a[0]);
for(int i=1;i<n;i++) {
a[i].x-=a[0].x;
a[i].y-=a[0].y;
a[i].a2=atan2(a[i].y,a[i].x);
}
sort(a.begin(),a.end(),[](Point a,Point b) {
if(a.a2==b.a2) return a.x<b.x;
return a.a2<b.a2;
});
convex.push_back(a[0]);
for(int i=1;i<n;i++) {
if(convex.size()<3) {
convex.push_back(a[i]);
}
else {
while(convex.size()>=3) {
Vector x(convex[convex.size()-2],convex[convex.size()-1]),
y(convex[convex.size()-1],a[i]);
if(x.x*y.y - x.y*y.x <=0) convex.pop_back();
else break;
}
convex.push_back(a[i]);
}
}
return convex;
}
int check(vector<Point> &a,vector<Point> &convex) {
queue<Point> A,B;
for(auto x:a) A.push(x);
for(auto x:convex) B.push(x);
if(A.size()!=B.size()) {
return 0;
}
for(int i=0;i<n;i++) {
if(A.front().id==B.front().id) break;
A.push(A.front());
A.pop();
}
while(!A.empty()) {
if(A.front().id==B.front().id) {
A.pop(),B.pop();
}
else {
return 0;
}
}
return 1;
}
void solve() {
cin>>n;
set<Point> st;
for(int i=1;i<=n;i++) {
long long x,y;
cin>>x>>y;
a.push_back(Point(x,y,i-1));
}
for(int i=0;i<n;i++) st.insert(a[i]);
if(st.size()!=n) {
return(void)(cout<<"No");
}
vector<Point> convex = getConvex(a);
// for(auto x:convex) cout<<x.id<<endl;
if(check(a,convex)) return(void)(cout<<"Yes");
reverse(a.begin(),a.end());
if(check(a,convex)) return(void)(cout<<"Yes");
cout<<"No";
}
/*
(1,0)
(0,1)
a.x*b.y-a.y*b.x>0 a在b右侧
*/
int main() {
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
int t=1;
// cin>>t;
while(t--)
solve();
}
/*
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3664kb
input:
3 0 0 1 0 0 1
output:
Yes
result:
ok answer is YES
Test #2:
score: 0
Accepted
time: 1ms
memory: 4072kb
input:
4 0 0 0 1 1 1 1 0
output:
Yes
result:
ok answer is YES
Test #3:
score: 0
Accepted
time: 1ms
memory: 3896kb
input:
4 0 0 0 3 1 2 1 1
output:
Yes
result:
ok answer is YES
Test #4:
score: 0
Accepted
time: 1ms
memory: 3696kb
input:
3 0 0 0 0 0 0
output:
No
result:
ok answer is NO
Test #5:
score: 0
Accepted
time: 0ms
memory: 4064kb
input:
5 1 0 4 1 0 1 2 0 3 2
output:
No
result:
ok answer is NO
Test #6:
score: 0
Accepted
time: 0ms
memory: 3852kb
input:
5 0 0 1000000000 0 1000000000 500000000 1000000000 1000000000 0 1000000000
output:
No
result:
ok answer is NO
Test #7:
score: 0
Accepted
time: 0ms
memory: 3964kb
input:
5 0 0 1000000000 0 1000000000 499999999 1000000000 1000000000 0 1000000000
output:
No
result:
ok answer is NO
Test #8:
score: 0
Accepted
time: 1ms
memory: 3948kb
input:
5 0 0 999999999 0 1000000000 50000000 999999999 1000000000 0 1000000000
output:
Yes
result:
ok answer is YES
Test #9:
score: -100
Wrong Answer
time: 55ms
memory: 37784kb
input:
128312 5578014 410408218 5585076 410404717 5588011 410403262 5588473 410403033 5589740 410402405 5593295 410400643 5593751 410400417 5597248 410398684 5598935 410397848 5600618 410397014 5605185 410394751 5610514 410392111 5614281 410390245 5617263 410388768 5621142 410386847 5630840 410382045 56310...
output:
No
result:
wrong answer expected YES, found NO