QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#313753#7730. Convex CheckerOMoonStarsWA 35ms13060kbC++172.6kb2024-01-24 23:01:082024-07-04 19:17:55

Judging History

你现在查看的是最新测评结果

  • [2024-07-04 19:27:17]
  • hack成功,自动添加数据
  • (/hack/727)
  • [2024-07-04 19:17:55]
  • 自动重测本题所有获得100分的提交记录
  • 测评结果:WA
  • 用时:35ms
  • 内存:13060kb
  • [2024-07-04 19:17:30]
  • hack成功,自动添加数据
  • (/hack/726)
  • [2024-01-24 23:01:09]
  • 评测
  • 测评结果:100
  • 用时:41ms
  • 内存:13244kb
  • [2024-01-24 23:01:08]
  • 提交

answer

#include<algorithm>
#include<array>
#include<bitset>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<unordered_map>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define endl '\n'
using namespace std;
using ll=long long;
using db=double;
using pii=pair<int,int>;
const int inf=0x3f3f3f3f;
const int mod=998244353;
const db eps=1e-8;
const db PI=acos(-1);
const int N=2e5+10,M=1e3+10;
//?????????????,????????
//???????:?????????(n-2)*PI;?????,??????cos,????-1~1,??acos????
bool sgn(db x){
    return x>eps?1:(x<-eps?-1:0);
}
inline int cmp(db a,db b){return sgn(a-b);}//a=b??0,a>b??1,a<b??-1
struct point{
    db x,y;
    point operator + (const point &a)const{
        return {x+a.x,y+a.y};
    }
    point operator - (const point &a)const{
        return {x-a.x,y-a.y};
    }
    point operator * (const db a)const{
        return {x*a,y*a};
    }
    bool operator<(point p)const{//?????,??????
        int c=cmp(x,p.x);
        if(c)return c==-1;
        return cmp(y,p.y)==-1;
    }
    db abs(){return sqrt(abs2());}
    db abs2(){return x*x+y*y;}
    db distTo(point p){return (*this-p).abs();}
};
double dot(const point &a,const point &b){
    return a.x*b.x+a.y*b.y;
}
double det(const point &a,const point &b){
    return a.x*b.y-a.y*b.x;
}
bool turn_left(const point &a,const point &b,const point &c){
    return sgn(det(b-a,c-a))>0;
}
bool convex_hull(vector<point> a)
{
    sort(a.begin(), a.end()); // ? ? ?: less <pair >
    vector<point> ret;
    for (int i = 0; i < (int)a.size(); i++)
    {
        while (ret.size() > 1 && !turn_left(ret[ret.size() - 2], ret[ret.size() - 1], a[i]))
            return false;
        ret.push_back(a[i]);
    }
    int fixed = (int)ret.size();
    for (int i = (int)a.size() - 2; i >= 0; --i)
    {
        while (ret.size() > fixed && !turn_left(ret[ret.size() - 2], ret[ret.size() - 1], a[i]))
            return false;
        ret.push_back(a[i]);
    }
    ret.pop_back();
    return true;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<point>p(n);
    for(auto &[x,y]:p)
        cin >> x >> y;
    if(convex_hull(p))
    {
        db sum=0;
        for(int i=0;i<n;i++)
        {
            point p1=p[i],p2=p[(i+1)%n],p3=p[(i+2)%n];
            db cost=dot(p2-p1,p2-p3)/p1.distTo(p2)/p2.distTo(p3);
            db theta=acos(cost);
            sum+=theta;
        }
        if(cmp(sum,(n-2)*PI))cout << "No" << endl;
        else cout << "Yes" << endl;
    }
    else cout << "No" << endl;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 4232kb

input:

3
0 0
1 0
0 1

output:

Yes

result:

ok answer is YES

Test #2:

score: 0
Accepted
time: 0ms
memory: 4160kb

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: 4032kb

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: 3912kb

input:

3
0 0
0 0
0 0

output:

No

result:

ok answer is NO

Test #5:

score: 0
Accepted
time: 0ms
memory: 4004kb

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: 3744kb

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: 3720kb

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: 0ms
memory: 4080kb

input:

5
0 0
999999999 0
1000000000 50000000
999999999 1000000000
0 1000000000

output:

Yes

result:

ok answer is YES

Test #9:

score: 0
Accepted
time: 35ms
memory: 11952kb

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:

Yes

result:

ok answer is YES

Test #10:

score: -100
Wrong Answer
time: 34ms
memory: 13060kb

input:

128086
149550602 509469827
149551059 509465022
149551336 509462107
149551964 509455497
149552572 509449094
149553350 509440895
149553656 509437667
149554161 509432339
149554254 509431357
149554545 509428284
149555017 509423299
149555366 509419611
149555842 509414580
149556382 509408867
149556564 509...

output:

No

result:

wrong answer expected YES, found NO