/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 332.0 KiB
#2 Accepted 2ms 516.0 KiB
#3 Accepted 2ms 352.0 KiB
#4 Accepted 2ms 328.0 KiB
#5 Accepted 2ms 328.0 KiB
#6 Accepted 2ms 504.0 KiB
#7 Accepted 2ms 772.0 KiB
#8 Accepted 2ms 328.0 KiB
#9 Accepted 2ms 740.0 KiB
#10 Accepted 2ms 492.0 KiB
#11 Accepted 2ms 332.0 KiB
#12 Accepted 2ms 488.0 KiB
#13 Accepted 2ms 492.0 KiB
#14 Accepted 2ms 328.0 KiB
#15 Accepted 2ms 496.0 KiB
#16 Accepted 3ms 588.0 KiB
#17 Accepted 2ms 512.0 KiB
#18 Accepted 3ms 448.0 KiB
#19 Accepted 3ms 484.0 KiB
#20 Accepted 3ms 544.0 KiB
#21 Accepted 3ms 544.0 KiB
#22 Accepted 3ms 584.0 KiB
#23 Accepted 3ms 688.0 KiB
#24 Accepted 3ms 600.0 KiB
#25 Accepted 3ms 608.0 KiB
#26 Accepted 3ms 460.0 KiB
#27 Accepted 2ms 540.0 KiB
#28 Wrong Answer 2ms 544.0 KiB
#29 Accepted 2ms 332.0 KiB

Code

#include<bits/stdc++.h>
using namespace std;

#define nl '\n'
#define ll long long
#define int long long
#define pii pair<int, int> 

long double eps = 1e-14;
int sign(long double x){return (x>eps)-(x<-eps);}
struct P{
    long double x , y;
    P(){x = 0, y = 0;}
    P(long double x, long double y) :  x(x),y(y){}
    P operator - (const P& a)const{
        return P(x-a.x, y-a.y);
    }

    long double operator * (const P& b){
        return x*b.y - y*b.x;
    }
    int orientation(const P& a, const P& b)const{
        return sign((a - *this)*(b - *this));
    }
};
istream &operator>>(istream &in, P& p){return in>>p.x>>p.y;}
ostream &operator<<(ostream &out, P& p){return out<<p.x<<p.y;}
inline long double cross(P a, P b){return a.x*b.y - a.y*b.x;}
bool is_seg(P a, P b,P p){
    if(fabs(cross(p-b, a-b))<eps){
        if(p.x<min(a.x, b.x) - eps || p.x>max(a.x,b.x)+eps)
            return false;
        if(p.y<min(a.y, b.y) - eps || p.y>max(a.y,b.y)+eps)
            return false;
        return true;
    }
    return false;
}
bool is_on(vector<P>& p, const P& z){
    int n = p.size();
    for(int i = 0; i < n ; i++){
        if(is_seg(p[i],p[i+1%n],z)) return 1;
    }
    return 0;
}

int winding_number(vector<P>& p, const P& z){
    if(is_on(p,z))return 1e9;
    int n = p.size(),ans = 0;
    for(int i = 0; i < n; i++){
        int j = (i+1)%n;
        bool below = p[i].y<z.y;
        if(below !=(p[j].y < z.y)){
            auto ori = z.orientation(p[j],p[i]);
            if(ori == 0)return 0;
            if(below == (ori > 0))ans+= below ? 1: -1;
        }
    }
    return ans;
}

int in_poly(vector<P>& p, const P& z){
    int k = winding_number(p, z);
    return k == 1e9 ? 0 : k == 0 ? 1: -1;
}

void solve(){
    int n; cin >> n;
    vector<P> points(n);
    for(int i = 0; i < n; i++)  cin>>points[i];
    P z;
    cin>>z;
    int ans = in_poly(points, z);
    if(ans == 1)    cout<<"NO\n";
    else cout<<"YES\n";
}

int32_t main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int t = 1, tc = 0;
    // cin >> t ;
    while(t--){
        // cout << "Case " << ++tc  << ": ";
        solve();
    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1145 Nobita's Love for Shizuka
Contest
LU IUJPC : Sylhet Division 2024
Language
C++17 (G++ 13.2.0)
Submit At
2024-12-09 09:38:12
Judged At
2024-12-09 09:38:12
Judged By
Score
98
Total Time
3ms
Peak Memory
772.0 KiB