[UVA] 11835 - Formula 1
Formula 1
The Formula 1 season consists of a series of races, known as Grand Prix, organized by the
International Federation of Automobile (FIA). The results of each Grand Prix are combined
to determine Pilots' World Championship. More specifically, for each race some points are
distributed to pilots, depending on their classification in the race. At the end of the season,
the pilot who has earned the most points is declared the World Champion.
| Formula 1 |
Formula 1 organisers change constantly the competition rules, aiming to provide more excitement to fans. One rule modified for the 2010 season was the distribution of points in each Grand Prix. Since 2003, the scoring rule rewarded the top eight pilots, according to the following table
| Place | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
| Points | 10 | 8 | 6 | 5 | 4 | 3 | 2 | 1 |
That is, the winning driver received 10 points, second place received 8 points, and so on. In the 2010 season the top ten will receive points, obeying the following table:
| Place | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| Points | 25 | 18 | 15 | 12 | 10 | 8 | 6 | 4 | 2 | 1 |
The change in the scoring system led to much speculation about what would have been the effect to the World Championship in the past if the new score had been used. For example, would Lewis Hamilton have been champion in 2008, considering he and Felipe Massa were separated by just one point? To end the speculation, FIA hired you to write a program that, given the results of each race of a season determines the World Champion for different scoring systems.
Input
The input contains several test cases. The first line of a test case contains two integers G and P separated by a blank space, indicating the number of Grand Prix ( 1The last test case is followed by a line containing only two zeros separated by a blank space.
Output
For each scoring system in the input your program must print one line, containing the identifier of the World Champion. If more than one pilot are World Champions (ie, if there is a tie), the line must contain all World Champions, in increasing order of identifier, separated by a space.
Sample Input
1 3 3 2 1 3 3 5 3 2 3 5 3 1 3 1 1 1 3 10 1 2 3 4 5 6 7 8 9 10 10 1 2 3 4 5 6 7 8 9 9 10 1 2 3 4 5 6 7 8 2 5 5 4 3 2 1 3 10 5 1 2 4 1 3 4 2 4 1 3 2 2 3 3 2 1 3 5 4 2 0 0
Sample Output
3 3 1 2 3 3 3 2 4 4
題目描述:
給你每一場的選手名次, 根據不同的計分方式輸出第一名的選手, 而每組測資可能會有很多場次,
積分是累計的, 若有相同積分則由小到大輸出。
#include <stdio.h>
#include <algorithm>
using namespace std;
int main() {
int G, Q, S, K;
while(scanf("%d %d", &G, &Q) == 2) {
if(G == 0) break;
int g[105][105], i, j, k, x;
for(i = 0; i < G; i++)
for(j = 0; j < Q; j++)
scanf("%d", &x), g[i][x-1] = j+1;
scanf("%d", &S);
while(S--) {
int score[105] = {};
scanf("%d", &K);
for(i = 0; i < K; i++) {
scanf("%d", &k);
for(j = 0; j < G; j++)
score[g[j][i]] += k;
}
int mx = 0, first = 0;
for(i = 1; i <= Q; i++)
mx = max(mx, score[i]);
for(i = 1; i <= Q; i++)
if(score[i] == mx) {
if(first) putchar(' ');
first = 1;
printf("%d", i);
}
puts("");
}
}
return 0;
}