QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#279257 | #7730. Convex Checker | PhantomThreshold | WA | 1ms | 3864kb | C++20 | 1.5kb | 2023-12-08 14:44:40 | 2023-12-08 14:44:40 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long db;
struct point
{
db x,y;
point operator+(const point &p)const{return {x+p.x,y+p.y};}
point operator-(const point &p)const{return {x-p.x,y-p.y};}
db operator*(const point &p)const{return x*p.y-y*p.x;}
db operator^(const point &p)const{return x*p.x+y*p.y;}
point turn90()const{return (point){-y,x};}
db abs2()const{return x*x+y*y;}
double abs()const{return hypot(x,y);}
db dis2(const point &p)const{return (*this-p).abs2();}
double dis(const point &p)const{return (*this-p).abs();}
bool operator<(const point &p)const{/*int pu=getP(),pv=p.getP();if(pu!=pv)return pu<=pv;*/return *this*p>0;}
friend istream& operator>>(istream &is,point &p){is>>p.x>>p.y;return is;}
friend ostream& operator<<(ostream &os,const point &p){os<<p.x<<' '<<p.y;return os;}
};
const double pi=acos(-1.),eps=1e-6;
int main()
{
ios_base::sync_with_stdio(false);
int n;
cin>>n;
vector<point> a(n+5);
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
double turn=0.;
for(int i=1;i<=n;i++)
{
turn+=atan2((a[i%n+1]-a[i])*(a[(i+1)%n+1]-a[i%n+1]),(a[i%n+1]-a[i])^(a[(i+1)%n+1]-a[i%n+1]));
}
if(turn<0)
{
turn=-turn;
reverse(a.begin()+1,a.begin()+n+1);
}
if(abs(turn-2*pi)>eps)
{
cout<<"No\n";
return 0;
}
for(int i=1;i<=n;i++)
{
point pre=a[i],now=a[i%n+1],nxt=a[(i+1)%n+1];
//(a^2+b^2-c^2)/2ab=cost
if(acos((pre.dis2(now)+now.dis2(nxt)-pre.dis2(nxt))/(2*pre.dis(now)*now.dis(nxt)))<0)
{
cout<<"No\n";
return 0;
}
}
cout<<"Yes\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3756kb
input:
3 0 0 1 0 0 1
output:
Yes
result:
ok answer is YES
Test #2:
score: 0
Accepted
time: 0ms
memory: 3524kb
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: 3864kb
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: 3596kb
input:
3 0 0 0 0 0 0
output:
No
result:
ok answer is NO
Test #5:
score: 0
Accepted
time: 0ms
memory: 3740kb
input:
5 1 0 4 1 0 1 2 0 3 2
output:
No
result:
ok answer is NO
Test #6:
score: -100
Wrong Answer
time: 0ms
memory: 3604kb
input:
5 0 0 1000000000 0 1000000000 500000000 1000000000 1000000000 0 1000000000
output:
Yes
result:
wrong answer expected NO, found YES