Advertisement
Guest User

Untitled

a guest
May 19th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.93 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Dot_and_poligon {
  4.  
  5.     public static void main(String[] args) {
  6.         Scanner sc = new Scanner(System.in);
  7.         int n = sc.nextInt();
  8.         double arrx[] = new double[n + 1];
  9.         double arry[] = new double[n + 1];
  10.         for (int i = 0; i < n; i++) {
  11.             arrx[i] = sc.nextDouble();
  12.             arry[i] = sc.nextDouble();
  13.         }
  14.         double x = sc.nextDouble();
  15.         double y = sc.nextDouble();
  16.         arrx[n] = arrx[0];
  17.         arry[n] = arry[0];
  18.         int ch = -1;
  19.         for (int i = 0; i < n + 1; i++) {
  20.             double d = arrx[i] * arry[i + 1] - arrx[i + 1] * arry[i] + arrx[i + 1] * y - x * arry[i + 1] + x * arry[i]
  21.                     - arrx[i] * y;
  22.             if (ch == -1) {
  23.                 if (d > 0)
  24.                     ch = 1;
  25.                 if (d < 0)
  26.                     ch = 0;
  27.             } else {
  28.                 if (d < 0 && ch == 1) {
  29.                     ch = 2;
  30.                 }
  31.                 if (d > 0 && ch == 0) {
  32.                     ch = 2;
  33.                 }
  34.             }
  35.         }
  36.         if (ch != 2)
  37.             System.out.println("YES");
  38.         else
  39.             System.out.println("NO");
  40.         sc.close();
  41.  
  42.     }
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement