// Topcoder SRM 577 DIV 2 L2 EllysRoomAssignmentsDiv2
import java.util.*;
import java.math.*;
//rename the class name before submitting
public class EllysRoomAssignmentsDiv2 {
public static void main(String[] args) {
EllysRoomAssignmentsDiv2 obj = new EllysRoomAssignmentsDiv2();
System.out.println(
obj.getProbability(
new String[]
{ "1168"
}
));
}
public double getProbability(String[] ratings) {
ArrayList<Integer> all = new ArrayList<Integer>();
StringBuilder sb = new StringBuilder("");
for (String r : ratings) {
sb.append(r);
}
String[] rr = sb.toString().split(" ");
for (String s : rr) {
all.add(Integer.valueOf(s));
}
int rating = all.get(0);
Collections.sort(all, Collections.reverseOrder());
int N = all.size();
if (N <= 20)
return 1;
if (rating == all.get(0))
return 1;
int nrooms = N / 20;
if (N % 20 != 0)
nrooms += 1;
if (nrooms == 1)
return 0;
else {
for (int i = 0; i < nrooms; i++) {
if (rating == all.get(i))
return 0;
}
return 1.0 / nrooms;
}
}
}
No comments:
Post a Comment