import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.util.Locale; import java.util.Scanner; /** * Bowser's Army * * For the UMD High School Programming Contest, 2009. * @author Chau-Wen Tseng */ public class Team { static final int maxTeams = 10000; static final int maxMemberType = 1000; static String memberTypes[] = new String[maxMemberType]; static int numMemberTypes = 0; static int memberNames[]; static int allMembers = 0; static int numTeams = 0; static String teamID[] = new String [maxTeams]; static int members[][]; static int teamLeader[] = new int [maxTeams]; static boolean lowestLvl[] = new boolean [maxTeams]; static double VIdist[] = new double [maxTeams];; static int bestSubgroup [][] = new int [maxTeams][]; static double bestVIdist[] = new double [maxTeams]; static String format1 = "###0.000000" ; static DecimalFormat fm1 = new DecimalFormat( format1, new DecimalFormatSymbols(Locale.US)); static int memberType(String s) { for (int i = 0; i < numMemberTypes; i++) { if (s.equals(memberTypes[i])) return i; } // System.err.println("Illegal member type: " + s); return -1; } static String memberName(int t) { return memberTypes[t]; } static int teamNum(String ID) { for (int i=0; i< numTeams; i++) { if (teamID[i].equals(ID)) return i; } // System.err.println("Can't find team " + ID); return -1; } public static void main(String[] args) throws Exception { String s; // initialization for (int t = 0; t NONE"); else System.out.println(s + " > " + teamID[t]); } else if (s.equals("COMMANDTEAM")) { int group[] = new int [maxTeams]; int groupSize = 0; // read in remainder of group while (lsc.hasNext()) { s = lsc.next(); tnum = teamNum(s); if (tnum < 0) { System.out.println("ILLEGAL COMMANDTEAM MEMBER" + s); } else { group[groupSize++] = tnum; } } // check whether legal group if (checkGroup(groupSize, group)) { System.out.println("YES"); } else { System.out.println("NO"); } } else if (s.equals("BESTCOMMAND")) { tnum = numTeams-1; System.out.print(fm1.format(VIdist[numTeams - 1])); for (int i = 0; i< bestSubgroup[tnum].length; i++) { System.out.print(" "+teamID[bestSubgroup[tnum][i]]); } System.out.println(); } } } } static boolean checkGroup(int gsize, int group[]) { for (int i = 0; i= 0) { for (int g = 0; g < gsize; g++) { if (group[g] == commander) found++; } commander = teamLeader[commander]; } if (found != 1) return false; } return true; } static void computeVIdist() { // count up total number of members from leaves allMembers = 0; for (int i = 0; i 0) System.out.println("\tLeader = " + teamID[teamLeader[num]]); System.out.println("\tEnrollment = "+ all); for (int k = 0; k 0) { double percentage = ((double) n) / teamSize; double p_xk = p_x * percentage; sum += p_xk * Math.log10(p_xk); } } return (p_x * Math.log10(p_x)) - (2*sum); } }