Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //is a point inside a convex polygon? | https://informatics.mccme.ru/mod/statements/view3.php?id=41131&chapterid=451
- //Made by @maximihajlov | PhTS2020a | 30/05/2019
- import java.util.Scanner;
- public class TaskD {
- public static class Point {
- public Point(double x0, double y0) {
- x = x0;
- y = y0;
- }
- double x;
- double y;
- }
- public static int N;
- public static Point Poly[];
- public static boolean solve(Point spot) {
- int i;
- int j;
- boolean ans = false;
- for (i = 0, j = Poly.length - 1; i < Poly.length; j = i++) {
- if ((Poly[i].y > spot.y) != (Poly[j].y > spot.y) &&
- (spot.x < (Poly[j].x - Poly[i].x) * (spot.y - Poly[i].y) / (Poly[j].y - Poly[i].y) + Poly[i].x)) {
- ans = !ans;
- }
- }
- return ans;
- }
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- N = sc.nextInt();
- Poly = new Point[N];
- for (int i = 0; i < N; i++) Poly[i] = new Point(sc.nextDouble(), sc.nextDouble()); //Polygon input
- Point spot = new Point(sc.nextDouble(), sc.nextDouble());//xPoint
- if (solve(spot)) System.out.println("YES");
- else System.out.println("NO");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement