package srm500.div2.level2; import java.util.ArrayList; import java.util.List; public class MafiaGame { public static final int VULNERABLE = -1; public double probabilityToLose(int N, int[] decisions) { // boolean[] vulnerable = new boolean[N]; // for (int i = 0; i < vulnerable.length; i++) { // vulnerable[i] = true; // } int[] votes = new int[N]; int votedNum = 0; for (int i = 0; i < decisions.length; i++) { if (VULNERABLE != votes[decisions[i]]) { votes[decisions[i]]++; votedNum++; } } // find the one has not vote for (int i = votedNum; i < N; i++) { int[] smallest = findSmallestVotesIndex(votes); } return 0.0; } public static int[] findSmallestVotesIndex(int[] votes) { int min = Integer.MAX_VALUE; for (int i = 0; i < votes.length; i++) { if (votes[i] < min && votes[i] > VULNERABLE) { min = votes[i]; } } List<Integer> indices = new ArrayList<Integer>(); for (int i = 0; i < votes.length; i++) { if (votes[i] == min) { indices.add(i); } } int[] ret = new int[indices.size()]; for (int i = 0; i < ret.length; i++) { ret[i] = indices.get(i); } return ret; } public static void clearVotes(int[] votes) { for (int i = 0; i < votes.length; i++) { votes[i] = 0; } } }