/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Accepted 2ms 520.0 KiB
#3 Accepted 1ms 540.0 KiB
#4 Accepted 2ms 512.0 KiB
#5 Accepted 2ms 332.0 KiB
#6 Accepted 1ms 540.0 KiB
#7 Accepted 1ms 588.0 KiB
#8 Accepted 1ms 540.0 KiB
#9 Accepted 1ms 540.0 KiB
#10 Accepted 2ms 576.0 KiB
#11 Accepted 1ms 544.0 KiB
#12 Accepted 1ms 588.0 KiB
#13 Accepted 2ms 328.0 KiB
#14 Accepted 1ms 540.0 KiB
#15 Accepted 1ms 552.0 KiB
#16 Accepted 2ms 568.0 KiB
#17 Accepted 2ms 540.0 KiB
#18 Accepted 2ms 584.0 KiB
#19 Accepted 1ms 540.0 KiB
#20 Accepted 2ms 332.0 KiB
#21 Accepted 1ms 812.0 KiB
#22 Accepted 2ms 364.0 KiB
#23 Accepted 1ms 540.0 KiB
#24 Accepted 2ms 532.0 KiB
#25 Accepted 1ms 540.0 KiB
#26 Accepted 2ms 512.0 KiB
#27 Accepted 1ms 560.0 KiB
#28 Wrong Answer 2ms 328.0 KiB
#29 Accepted 2ms 508.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> 

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

    ll 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 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 08:44:23
Judged At
2024-12-09 08:44:23
Judged By
Score
98
Total Time
2ms
Peak Memory
812.0 KiB