Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- #include <cmath>
- using namespace std;
- struct pt {
- int x,y;
- } a[111111],p;
- int n;
- int det ( pt a, pt b, pt c )
- {
- return (b.x - a.x) * (c.y - b.y) - (c.x - b.x ) * (b.y - a.y );
- }
- bool intersect( pt a,pt b,pt c,pt d )
- {
- return det(a,b,c) * det(a,b,d) <= 0 && det(c,d,a) * det(c,d,b) < 0;
- }
- int main()
- {
- scanf("%d",&n);
- for ( int i = 1; i <= n; i++ )
- scanf("%d%d",&a[i].x,&a[i].y);
- scanf("%d%d",&p.x,&p.y);
- if ( det(a[1],a[n],p) > 0 || det(a[1],a[2],p) < 0 ) { puts("NO"); return 0; }
- int l = 2, r = n;
- while ( r - l > 1 ) {
- int m = (r + l) / 2;
- if ( det(a[1],a[m],p) >= 0 ) l = m;
- else r = m;
- }
- if ( intersect(a[1],p,a[l],a[r]) ) puts("NO");
- else puts("YES");
- }
Advertisement
Add Comment
Please, Sign In to add comment