7-40 奥运排行榜 (25 分)

7-40 奥运排行榜 (25 分)

每年奥运会各大媒体都会公布一个排行榜,但是细心的读者发现,不同国家的排行榜略有不同。比如中国金牌总数列第一的时候,中国媒体就公布“金牌榜”;而美国的奖牌总数第一,于是美国媒体就公布“奖牌榜”。如果人口少的国家公布一个“国民人均奖牌榜”,说不定非洲的国家会成为榜魁…… 现在就请你写一个程序,对每个前来咨询的国家按照对其最有利的方式计算它的排名。

输入格式:

输入的第一行给出两个正整数$N$和$M$(≤224,因为世界上共有224个国家和地区),分别是参与排名的国家和地区的总个数、以及前来咨询的国家的个数。为简单起见,我们把国家从0 ~ $N$−1编号。之后有$N$行输入,第i行给出编号为i−1的国家的金牌数、奖牌数、国民人口数(单位为百万),数字均为[0,1000]区间内的整数,用空格分隔。最后面一行给出$M$个前来咨询的国家的编号,用空格分隔。

输出格式:

在一行里顺序输出前来咨询的国家的排名:计算方式编号。其排名按照对该国家最有利的方式计算;计算方式编号为:金牌榜=1,奖牌榜=2,国民人均金牌榜=3,国民人均奖牌榜=4。输出间以空格分隔,输出结尾不能有多余空格。

若某国在不同排名方式下有相同名次,则输出编号最小的计算方式。

输入样例:

1
2
3
4
5
6
4 4
51 100 1000
36 110 300
6 14 32
5 18 40
0 1 2 3

输出样例:

1
1:1 1:2 1:3 1:4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144

#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

struct country {
int number; //国家编号
int prizes[3]; //prizes[0]代表金牌数量,prizes[1]代表奖牌数量,prizes[2]代表国民人口数量
int rank;
};

int N, M;
//countries1按金牌排名,countries2按奖牌排名,countries3按国民人均金牌排名,countries4按人均奖牌排名
vector<country> countries1, countries2, countries3, countries4;

bool cmp1(country c1, country c2);
bool cmp2(country c1, country c2);
bool cmp3(country c1, country c2);
bool cmp4(country c1, country c2);
void generateRank(int condition);
int findRank(int condition, int number);

int main() {
scanf("%d %d", &N, &M);
for(int i = 0; i < N; i++) {
country tempCountry;
scanf("%d %d %d", &tempCountry.prizes[0], &tempCountry.prizes[1], &tempCountry.prizes[2]);
tempCountry.number = i;
countries1.push_back(tempCountry);
countries2.push_back(tempCountry);
countries3.push_back(tempCountry);
countries4.push_back(tempCountry);
}
sort(countries1.begin(), countries1.end(), cmp1);
sort(countries2.begin(), countries2.end(), cmp2);
sort(countries3.begin(), countries3.end(), cmp3);
sort(countries4.begin(), countries4.end(), cmp4);
for(int i = 0; i < 4; i++){
generateRank(i);
}
for(int i = 0; i < M; i++) {
int query;
scanf("%d", &query);
int ranks[4];
for(int j = 0; j < 4; j++) {
ranks[j] = findRank(j + 1, query);
}
int minIndex = 0;
for(int j = 1; j < 4; j++) {
if(ranks[j] < ranks[minIndex]) {
minIndex = j;
}
}
printf("%d:%d", ranks[minIndex], minIndex + 1);
if(i == M - 1) {
printf("\n");
} else {
printf(" ");
}
}
return 0;
}

bool cmp1(country c1, country c2) {
return c1.prizes[0] > c2.prizes[0];
}

bool cmp2(country c1, country c2) {
return c1.prizes[1] > c2.prizes[1];
}

bool cmp3(country c1, country c2) {
return c1.prizes[0] * 1.0 / c1.prizes[2] > c2.prizes[0] * 1.0 / c2.prizes[2];
}

bool cmp4(country c1, country c2) {
return c1.prizes[1] * 1.0 / c1.prizes[2] > c2.prizes[1] * 1.0 / c2.prizes[2];
}

void generateRank(int condition) {
if(condition == 0) {
for(int i = 0; i < countries1.size(); i++) {
if(i > 0 && countries1[i].prizes[0] == countries1[i - 1].prizes[0]) {
countries1[i].rank = countries1[i - 1].rank;
} else {
countries1[i].rank = i;
}
}
} else if(condition == 1) {
for(int i = 0; i < countries2.size(); i++) {
if(i > 0 && countries2[i].prizes[1] == countries2[i - 1].prizes[1]) {
countries2[i].rank = countries2[i - 1].rank;
} else {
countries2[i].rank = i;
}
}
} else if(condition == 2) {
for(int i = 0; i < countries3.size(); i++) {
if(i > 0 && countries3[i].prizes[0] * 1.0 / countries3[i].prizes[2] == countries3[i - 1].prizes[0] * 1.0 / countries3[i - 1].prizes[2]) {
countries3[i].rank = countries3[i - 1].rank;
} else {
countries3[i].rank = i;
}
}
} else {
for(int i = 0; i < countries4.size(); i++) {
if(i > 0 && countries4[i].prizes[0] * 1.0 / countries4[i].prizes[2] == countries4[i - 1].prizes[0] * 1.0 / countries4[i - 1].prizes[2]) {
countries4[i].rank = countries4[i - 1].rank;
} else {
countries4[i].rank = i;
}
}
}
}

int findRank(int condition, int number) {
if(condition == 1) {
for(int i = 0; i < countries1.size(); i++) {
if(number == countries1[i].number) {
return countries1[i].rank + 1;
}
}
} else if(condition == 2) {
for(int i = 0; i < countries2.size(); i++) {
if(number == countries2[i].number) {
return countries2[i].rank + 1;
}
}
} else if(condition == 3) {
for(int i = 0; i < countries3.size(); i++) {
if(number == countries3[i].number) {
return countries3[i].rank + 1;
}
}
} else {
for(int i = 0; i < countries4.size(); i++) {
if(number == countries4[i].number) {
return countries4[i].rank + 1;
}
}
}
}
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×