A Contesting Decision
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 2065 | Accepted: 1508 |
Description
Judging a programming contest is hard work, with demanding contestants, tedious decisions,and monotonous work. Not to mention the nutritional problems of spending 12 hours with only donuts, pizza, and soda for food. Still, it can be a lot of fun.
Software that automates the judging process is a great help, but the notorious unreliability of some contest software makes people wish that something better were available. You are part of a group trying to develop better, open source, contest management software, based on the principle of modular design.
Your component is to be used for calculating the scores of programming contest teams and determining a winner. You will be given the results from several teams and must determine the winner.
Scoring
There are two components to a team's score. The first is the number of problems solved. The second is penalty points, which reflects the amount of time and incorrect submissions made before the problem is solved. For each problem solved correctly, penalty points are charged equal to the time at which the problem was solved plus 20 minutes for each incorrect submission. No penalty points are added for problems that are never solved.
So if a team solved problem one on their second submission at twenty minutes, they are charged 40 penalty points. If they submit problem 2 three times, but do not solve it, they are charged no penalty points. If they submit problem 3 once and solve it at 120 minutes, they are charged 120 penalty points. Their total score is two problems solved with 160 penalty points.
The winner is the team that solves the most problems. If teams tie for solving the most problems,then the winner is the team with the fewest penalty points.
Software that automates the judging process is a great help, but the notorious unreliability of some contest software makes people wish that something better were available. You are part of a group trying to develop better, open source, contest management software, based on the principle of modular design.
Your component is to be used for calculating the scores of programming contest teams and determining a winner. You will be given the results from several teams and must determine the winner.
Scoring
There are two components to a team's score. The first is the number of problems solved. The second is penalty points, which reflects the amount of time and incorrect submissions made before the problem is solved. For each problem solved correctly, penalty points are charged equal to the time at which the problem was solved plus 20 minutes for each incorrect submission. No penalty points are added for problems that are never solved.
So if a team solved problem one on their second submission at twenty minutes, they are charged 40 penalty points. If they submit problem 2 three times, but do not solve it, they are charged no penalty points. If they submit problem 3 once and solve it at 120 minutes, they are charged 120 penalty points. Their total score is two problems solved with 160 penalty points.
The winner is the team that solves the most problems. If teams tie for solving the most problems,then the winner is the team with the fewest penalty points.
Input
For the programming contest your program is judging, there are four problems. You are guaranteed that the input will not result in a tie between teams after counting penalty points.
Line 1 < nTeams >
Line 2 - n+1 < Name > < p1Sub > < p1Time > < p2Sub > < p2Time > ... < p4Time >
Line 1 < nTeams >
Line 2 - n+1 < Name > < p1Sub > < p1Time > < p2Sub > < p2Time > ... < p4Time >
The first element on the line is the team name, which contains no whitespace.Following that, for each of the four problems, is the number of times the team submitted a run for that problem and the time at which it was solved correctly (both integers). If a team did not solve a problem, the time will be zero. The number of submissions will be at least one if the problem was solved.
Output
The output consists of a single line listing the name of the team that won, the number of problems they solved, and their penalty points.
Sample Input
4 Stars 2 20 5 0 4 190 3 220 Rockets 5 180 1 0 2 0 3 100 Penguins 1 15 3 120 1 300 4 0 Marsupials 9 0 3 100 2 220 3 80
Sample Output
Penguins 3 475
SOLUTION:
package id1581; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.LinkedList; public class ContestingDecision { BufferedReader in = null; LinkedList<Team> teamList = null; final int TotalProblems = 4; final boolean DEBUG =false; public ContestingDecision(){ in = new BufferedReader(new InputStreamReader(System.in)); teamList = new LinkedList<Team>(); } private void start() throws IOException{ LinkedList<Team> mostSolvedTeams = new LinkedList<Team>(); int maxSolvedCounts = 0; int minPenalty = Integer.MAX_VALUE; int TeamNumber = 0; Team winner = null; String inStr = null; inStr = in.readLine(); TeamNumber = Integer.parseInt(inStr); // creat new Team for each input line for(int i = 0; i < TeamNumber; i++){ inStr = in.readLine(); teamList = splitStr2que(inStr,teamList); } // generate most solved problems Team Queue while(!teamList.isEmpty()){ if(teamList.peek().solvedNum > maxSolvedCounts){ maxSolvedCounts = teamList.peek().solvedNum; mostSolvedTeams.clear(); mostSolvedTeams.offer(teamList.poll()); } else if(teamList.peek().solvedNum == maxSolvedCounts) mostSolvedTeams.offer(teamList.poll()); else if(teamList.peek().solvedNum < maxSolvedCounts) teamList.remove(); } // find the lest penalty Team among most solved problems teams while(mostSolvedTeams.size() != 1){ if(mostSolvedTeams.peek().penaltyPoints < minPenalty){ minPenalty = mostSolvedTeams.peek().penaltyPoints; mostSolvedTeams.offer(mostSolvedTeams.poll()); } else mostSolvedTeams.remove(); } winner = mostSolvedTeams.poll(); // print out System.out.println(winner.teamName + " " + winner.solvedNum + " " + winner.penaltyPoints); } /* parse this line and make new Team, then push this new team to teamList */ private LinkedList<Team> splitStr2que(String str, LinkedList<Team> teamList){ String[] strArry = null; strArry = str.split(" "); teamList.offer(new Team(strArry)); return teamList; } public static void main(String[] args){ try { new ContestingDecision().start(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } private class Team{ String teamName = null; int solvedNum = 0; int penaltyPoints = 0; Problem[] problems = null; public Team(String[] strArry){ problems = new Problem[TotalProblems]; this.teamName = strArry[0]; System.out.println(""); for(int i = 0; i < TotalProblems; i++){ if(DEBUG) System.out.print(strArry[i * 2 + 1] + ' ' + strArry[i * 2 + 2] + " "); problems[i] = new Problem(Integer.parseInt(strArry[i * 2 + 1]), Integer.parseInt(strArry[i * 2 + 2])); } calculateScore(); } private void calculateScore(){ for(int i = 0; i < TotalProblems; i++){ if(problems[i].time != 0) solvedNum++; else continue; penaltyPoints += (problems[i].submitTimes - 1) * 20 + problems[i].time; } if(DEBUG)System.out.println("TotalProblems is " + TotalProblems + "penaltyPoints is " + penaltyPoints); } } private class Problem{ int submitTimes = 0; int time = 0; public Problem(int submitTimes, int time){ this.submitTimes = submitTimes; this.time = time; } } }