Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Convex_poligon {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int n = sc.nextInt();
- int arrx[] = new int[n + 2];
- int arry[] = new int[n + 2];
- for (int i = 0; i < n; i++) {
- arrx[i] = sc.nextInt();
- arry[i] = sc.nextInt();
- }
- arrx[n] = arrx[0];
- arry[n] = arry[0];
- arrx[n + 1] = arrx[1];
- arry[n + 1] = arry[1];
- int s;
- int ch = -1;
- for (int i = 0; i < n; i++) {
- s = arrx[i] * arry[i + 1] - arrx[i + 1] * arry[i] + arrx[i + 1] * arry[i + 2] - arrx[i + 2] * arry[i + 1]
- + arrx[i + 2] * arry[i] - arrx[i] * arry[i + 2];
- if (ch == -1) {
- if (s > 0)
- ch = 1;
- if (s < 0)
- ch = 0;
- } else {
- if (s < 0 && ch == 1) {
- ch = 2;
- break;
- }
- if (s > 0 && ch == 0) {
- ch = 2;
- break;
- }
- }
- }
- if (ch != 2)
- System.out.println("YES");
- else
- System.out.println("NO");
- sc.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement