-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10078_The_Art_Gallery.java
77 lines (57 loc) · 1.81 KB
/
10078_The_Art_Gallery.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import java.io.IOException;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
Scanner in = new Scanner(System.in);
int coords = in.nextInt();
while(coords > 0) {
int firstpx = in.nextInt();
int firstpy = in.nextInt();
int firstqx = in.nextInt();
int firstqy = in.nextInt();
int px = firstpx;
int py = firstpy;
int qx = firstqx;
int qy = firstqy;
int rx = in.nextInt();
int ry = in.nextInt();
int firstTurn = Turn(px,py,qx,qy,rx,ry);
boolean turnFound = false;
if (firstTurn != 0){
turnFound = true;
}
boolean correct = true;
for (int i = 3; i < coords; i++) {
px = qx;
py = qy;
qx = rx;
qy = ry;
rx = in.nextInt();
ry = in.nextInt();
int t = Turn(px,py,qx,qy,rx,ry);
if(!turnFound){
firstTurn = t;
} else if( t != 0 && t != firstTurn){
correct = false;
}
}
int t = Turn(rx,ry,firstpx,firstpy,firstqx,firstqy);
if( t != 0 && t != firstTurn){
correct = false;
}
if(!correct)
System.out.println("Yes");
else
System.out.println("No");
coords = in.nextInt();
}
}
private static int Turn(int px, int py, int qx, int qy, int rx, int ry) {
int t = ((qx-px) * (ry-qy)) - ((qy-py) * (rx-qx));
if(t == 0)
return 0;
if(t > 0)
return 1;
return -1;
}
}