-
Notifications
You must be signed in to change notification settings - Fork 3
/
beehives.java
52 lines (32 loc) · 931 Bytes
/
beehives.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
// Brett Fazio
import java.util.Scanner;
public class beehives {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (true) {
double dis = sc.nextDouble();
int hives = sc.nextInt();
if (dis == 0 && hives == 0) {
break;
}
double[] x = new double[hives];
double[] y = new double[hives];
for (int i =0; i < hives; i++) {
x[i] =sc.nextDouble();
y[i] = sc.nextDouble();
}
int sweet = hives;
outer : for (int i =0 ; i < hives; i++) {
for (int j = 0; j < hives; j++) {
if (i == j) continue;
double c = Math.sqrt((Math.pow(x[i]-x[j],2))+(Math.pow(y[i]-y[j],2)));
if (c <= dis) {
sweet--;
continue outer;
}
}
}
System.out.printf("%d sour, %d sweet%n", (hives-sweet),sweet);
}
}
}