Advertisement
Guest User

Untitled

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