
ZOJ Problem Set  2593
In this problem you are asked to implement the ranking system for a series of programming contests. Each contest runs using standard ACM ICPC rules, each run is judged and either accepted, or rejected. For each solved problem the penalty time is calculated as the time of the first accepted run in minutes plus twenty minutes for each unsuccessful run before the first successful run. For problems that are not solved no penalty time is considered. The teams are first ranked by the number of solved problems, next by the penalty time. Each team gets the highest possible rank, that is, if two or more teams have the same number of solved problems and the same penalty times, they all share the same place, highest from the range they occupy. So, for example, there can be two teams sharing the first place, followed by the third place team, and so on. The ranking of each team for the series of the contests is calculated as follows. Let P_{ij} be the number of problems solved by jth team in the ith contest. Let PM_{i} be the maximal number of problems solved by some team in the ith contest. The raw score of the jth team for this contest is RS_{ij} = P_{ij}/PM_{i} if PM_{i} > 0 and RS_{ij} = 0 if PM_{i} = 0. Let K_{i} be the number of teams take part in the ith contest. Calculate A_{i} and B_{i}, satisfying equations in the other case its total score is T_{j} = 0. Given the description of several contests, your task is for each team to calculate its total score. Input The input contains multiple test cases. The first line of the input is a single integer T (1 <= T <= 20) which is the number of test cases. T test cases follow, each preceded by a single blank line. The first line of each test case contains N  the number of teams (2 <= N <= 100), next N lines contain team names, length of each name does not exceed 100 characters. Let teams be numbered as they are given in the input file, starting from one. Next line contains M  the number of contests in a series (1 <= M <= 20). The descriptions of the contests follow. The first line of the contest descrption contains K_{i}  the number of teams that took part in this contest (2 <= K_{i} <= N) and the numbers of these teams. Next line contains PN_{i}  the number of problems in the contest (1 <= PN_{i} <= 26). Problems are identified using capital letters of the English alphabet, starting from 'A'. Next line contains RNi  the number of runs in the contest (0 <= RN_{i} <= 10 000). Next RN_{i} lines describe runs, each run description consists of four items, adjacent items are separated from each other by exactly one space. The items are: the number of the team, the letter of the problem, the time of the run in minutes and character '+' if the run is accepted, or '' if it is rejected. Runs are given in the order they were made, in particular run times are nondecreasing. Times are positive integers that do not exceed 300. Output For each test case, output N lines  the teams in the nonincreasing order of their total score. In case of equal total score, teams may be output in arbitary order. Print score aligned, so that there is exactly one space between the longest team name and the leftmost digit of the score, and all decimal points are in the same column. Print exactly four digits after the decimal point. Two consecutive cases should be separated by a single blank line. No blank line should be produced after the last test case. Sample Input 1 4 MosCow SU ThreeThreads SPb IMHO SPb FLY 3 3 1 2 3 5 10 1 A 30 + 1 B 80 + 2 A 85  2 C 90 + 1 E 101 + 3 A 130  3 A 140 + 1 D 150 + 3 D 280 + 3 E 299 + 2 2 3 2 3 2 A 160 + 2 B 245 + 3 A 280 + 3 1 3 4 4 6 1 A 50 + 3 A 50 + 1 A 155  3 A 160 + 1 B 180  4 A 200  Sample Output MosCow SU 2.0000 SPb IMHO 1.1667 ThreeThreads 1.1250 SPb FLY 0.0000 Author: Andrew Stankevich Source: Andrew Stankevich's Contest #5 