728x90
import java.util.*;
public class Main {
static int n,m,seen;
static double result;
static double []location;
static double [][]length;
public static void main(String args[]){
location = new double[200];
length = new double[200][200];
Scanner scanner = new Scanner(System.in);
int testcase = scanner.nextInt();
for(int i = 0; i < testcase; i++){
result = 0;
n = scanner.nextInt();
m = scanner.nextInt();
for(int j = 0; j < m; j++){
location[j] = scanner.nextDouble();
}
for(int k = 0; k < m-1; k++){
for(int l = k + 1; l < m; l++){
calculate(k,l);
}
}
result = optimize();
System.out.printf("%.2f\n", result);
}
}
public static void calculate(int k, int l){
double temp = location[l] - location[k];
length[l][k] = temp;
length[k][l] = temp;
}
public static double optimize(){
double lo = 0;
double hi = 240;
double mid;
for(int i = 0; i < 20; i++){
mid = (lo + hi) / 2;
if(decision(mid)){
lo = mid;
}
else
hi = mid;
}
return hi;
}
public static Boolean decision(double mid){
int now;
Boolean result;
for(int i = 0; i < m-1; i++){
seen = 1;
now = i;
result = nextvalue(now, mid);
if(result == true)
return true;
}
return false;
}
public static Boolean nextvalue(int a, double mid){
Boolean result;
for(int i = a + 1; i < m; i++){
if(length[a][i] >= mid){
seen++;
if(seen == n)
return true;
result = nextvalue(i, mid);
if(result == true)
return true;
break;
}
}
return false;
}
}
728x90
'코딩' 카테고리의 다른 글
알고스팟 자바(java) 해답 : TPATH (0) | 2021.05.14 |
---|---|
알고스팟 자바(java) 해답 : ARCTIC (0) | 2021.05.14 |
알고스팟 자바(java) 해답 : LAN (0) | 2021.05.14 |
알고스팟 자바(java) 해답 : FIRETRUCKS (0) | 2021.05.14 |
알고스팟 자바(java) 해답 : ROUTING(error) (0) | 2021.05.14 |