24h購物| | PChome| 登入
2013-06-29 22:29:11| 人氣508| 回應0 | 上一篇 | 下一篇

[UVA] 11835 - Formula 1

推薦 0 收藏 0 轉貼0 訂閱站台


  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 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 ( 1$ le$G$ le$100) and the number of pilots ( 1$ le$Q$ le$100). Pilots are identified by integers from 1 to P. Each of the following G lines indicates the result of a race, and contains Q integers separated by spaces. On each line, the (i)-th number indicates the order of arrival of pilot i in the race (the first number indicates the order of arrival of a pilot 1 in that race, the second number indicates the order of arrival of pilot 2 in that race and so on). The next line contains a single integer S indicating the number of scoring systems ( 1$ le$S$ le$10). After that, each of the following lines S contains a description of a scoring system. The description of a scoring system begins with an integer K ( 1$ le$K$ le$P), indicating the last finishing order to receive points, followed by a blank space, followed by K integers k0, k1,..., kn-1 ( 1$ le$ki$ le$100) separated by spaces, indicating the number of points to be assigned (the first integer indicates the points for first place, the second integer indicates the points for second place and so on).

The 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;
}


台長: Morris
人氣(508) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA][字串] 10197 - Learning Portuguese
此分類上一篇:[UVA] 11834 - Elevator

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文