-
Notifications
You must be signed in to change notification settings - Fork 0
/
CandidateCode.java
80 lines (68 loc) · 1.48 KB
/
CandidateCode.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
78
79
80
/* Read input from STDIN. Print your output to STDOUT*/
import java.util.*;
import java.text.DecimalFormat;
public class CandidateCode {
public static void main(String args[] ) throws Exception {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
while(--T>=0)
{
int L = sc.nextInt();
int coordinates[][] = new int[L][2];
for(int i=0;i<L;i++)
{
for(int j=0;j<2;j++){
coordinates[i][j]=sc.nextInt();
}
}
calcRadiusAndEffectiveSet(coordinates,L);
}
sc.close();
}
/*Calculation of the radius and effective set*/
public static void calcRadiusAndEffectiveSet(int coordMat[][],int row)
{
int curX;
int curY;
double x=0.00;
double y=0.00;
double rad=0.00;
double minRad=-1.0;
double minRadArr[]=new double[row];
int curRows=0,k=0,ctr=0;
while(curRows<row){
curX=coordMat[curRows][0];
curY=coordMat[curRows][1];
for(int i=0;i<row;i++)
{
if(i!=curRows){
x=Math.pow(curX-coordMat[i][0],2);
y=Math.pow(curY-coordMat[i][1],2);
rad=Math.sqrt(x+y);
if(minRad== -1.0)
minRad=rad;
if(minRad>rad)
{
minRad=rad;
}
minRadArr[k++]=rad;
}
}
//check counter for points in effective set
for(int i=0;i<row-1;i++)
{
if(minRadArr[i]<=minRad*2)
{
ctr++;
}
}
DecimalFormat df = new DecimalFormat("0.00");
System.out.println(df.format(minRad)+","+ctr);
//Resetting the counters and indexes
curRows+=1;
minRad= -1.0;
ctr=0;
k=0;
}
}
}