-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudy_9205.java
More file actions
84 lines (75 loc) · 1.53 KB
/
Study_9205.java
File metadata and controls
84 lines (75 loc) · 1.53 KB
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
78
79
80
81
82
83
84
import java.util.Scanner;
public class Study_9205{
static int MAX = 98765;
static class location{
int x;
int y;
location(){ }
location(int x, int y){
this.x = x;
this.y = y;
}
}
public static void floyd(int[][] d, int n) {
for(int k=0;k<n;k++) {
for(int i=0;i<n;i++) {
for(int j=0;j<n;j++){
if(d[i][j] > d[i][k] + d[k][j]) {
d[i][j] = d[i][k] + d[k][j];
}
}
}
}
}
public static int getdistance(location a, location b) {
int dis_x,dis_y;
if(a.x > b.x){
dis_x = a.x -b.x;
}else {
dis_x = b.x - a.x;
}
if(a.y > b.y) {
dis_y = a.y -b.y;
}else {
dis_y = b.y - a.y;
}
return dis_x + dis_y;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int TC = scanner.nextInt();
scanner.nextLine();
while(TC-->0) {
int N = scanner.nextInt();
int[][] distance = new int[N+2][N+2];
location[] loc = new location[N+2];
for(int i=0;i<N+2;i++) {
loc[i] = new location(scanner.nextInt(),scanner.nextInt());
}
for(int i=0;i<N+2;i++) {
for(int j =0 ;j<N+2;j++) {
if(i!=j) {
distance[i][j] = MAX;
}
}
}
for(int i=0;i<N+2;i++) {
for(int j =0 ;j<N+2;j++) {
if(i==j) {
continue;
}
int dis = getdistance(loc[i],loc[j]);
if(dis <= 1000) {
distance[i][j] =1;
}
}
}
floyd(distance,N+2);
if(0<distance[0][N+1] && distance[0][N+1] < MAX) {
System.out.println("happy");
}else {
System.out.println("sad");
}
}
}
}