-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCloud.java
executable file
·49 lines (49 loc) · 1.3 KB
/
Cloud.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
import java.io.*;
import java.util.*;
public class Cloud {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int cases = Integer.parseInt(br.readLine());
while(cases-- > 0) {
int n = Integer.parseInt(br.readLine());
double[] ang = new double[n];
for(int i = 0; i < n; i++) {
StringTokenizer st = new StringTokenizer(br.readLine());
int x = Integer.parseInt(st.nextToken());
int y = Integer.parseInt(st.nextToken());
int g = gcd(Math.abs(x), Math.abs(y));
ang[i] = Math.atan2(y/g, x/g);
}
System.out.println(isValid(ang) || isValid(rev(ang)) ? "YES" : "NO");
}
}
public static double[] rev(double[] in) {
double[] ret = new double[in.length];
for(int i = 0; i < in.length; i++) {
ret[ret.length-1-i] = in[i];
}
return ret;
}
public static boolean isValid(double[] ang) {
int min = 0;
for(int i = 1; i < ang.length; i++) {
if(ang[i] < ang[min]) {
min = i;
}
}
boolean ret = true;
for(int i = 1; i < ang.length; i++) {
int next = (min + i)%ang.length;
int a = (min+i-1)%ang.length;
if(ang[next] < ang[a]) {
ret = false;
}
}
return ret;
}
public static int gcd(int a, int b) {
if(b == 0) return a;
if(a == 0) return b;
return gcd(b, a%b);
}
}