//土尔逊Torson 编写于2023/4/12 #define _CRT_SECURE_NO_WARNINGS #include <cstdio> #include <algorithm> #include <stdlib.h> using namespace std; struct nation { //定义参加奥运会的国家参数 int aNum; //国家序号 int goldMedal; //金牌数 int medal; //奖牌数 int population;//million //人口(百万) double goldRatioPop; //金牌人口比例 double medalRationPop; //奖牌人口比例 int Rate_1_goldMedal; //金牌总数 排名 int Rate_2_medal; //奖牌总数 排名 int Rate_3_goldRatioPop; //金牌人口比例 排名 int Rate_4_medalRationPop; //奖牌人口比例 排名 }; bool comp0301(nation left, nation right) {//金牌总数 排名 if (left.goldMedal > right.goldMedal) { return true; } else if (left.goldMedal == right.goldMedal && left.aNum < right.aNum) { return true; } else { return false; } } bool comp0302(nation left, nation right) {//奖牌总数 排名 if (left.medal > right.medal) { return true; } else if (left.medal == right.medal && left.aNum < right.aNum) { return true; } else { return false; } } bool comp0303(nation left, nation right) {//金牌人口比例 排名 if (left.goldRatioPop > right.goldRatioPop) { return true; } else if (left.goldRatioPop == right.goldRatioPop && left.aNum < right.aNum) { return true; } else { return false; } } bool comp0304(nation left, nation right ) {//奖牌人口比例 排名 if (left.medalRationPop > right.medalRationPop) { return true; } else if (left.medalRationPop == right.medalRationPop && left.aNum < right.aNum) { return true; } else { return false; } } int main() { int N; int M; int arrM[30]; nation state[30]; while (scanf("%d %d", &N,&M) != EOF) {//获得 多组 第一行给出国家数N,要求排名的国家数M int aNum = 0; for (int i = 0; i < N; ++i) { //获得 国家各项参数,和初始化部分参数 scanf("%d %d %d", &state[i].goldMedal, &state[i].medal, &state[i].population); state[i].goldRatioPop = (double)state[i].goldMedal / (double)state[i].population; state[i].medalRationPop = (double)state[i].medal / (double)state[i].population; state[i].Rate_1_goldMedal = -1; state[i].Rate_2_medal = -1; state[i].Rate_3_goldRatioPop = -1; state[i].Rate_4_medalRationPop = -1; state[i].aNum = aNum; ++aNum; } for (int j = 0; j < M; ++j) { scanf("%d", &arrM[j]); } sort(state, state + N, comp0301);//金牌总数 排名 和记录排名 for (int i = 0; i < N; ++i) { if (i == 0) { state[i].Rate_1_goldMedal = i + 1; } else if (state[i].goldMedal == state[i - 1].goldMedal) { state[i].Rate_1_goldMedal = state[i - 1].Rate_1_goldMedal; } else { state[i].Rate_1_goldMedal = i + 1; } } sort(state, state + N, comp0302);//奖牌总数 排名 和记录排名 for (int i = 0; i < N; ++i) { if (i == 0) { state[i].Rate_2_medal = i + 1; } else if (state[i].medal == state[i - 1].medal) { state[i].Rate_2_medal = state[i - 1].Rate_2_medal; } else { state[i].Rate_2_medal = i + 1; } } sort(state, state + N, comp0303);//金牌人口比例 排名 和记录排名 for (int i = 0; i < N; ++i) { if (i == 0) { state[i].Rate_3_goldRatioPop = i + 1; } else if (state[i].goldRatioPop == state[i - 1].goldRatioPop) { state[i].Rate_3_goldRatioPop = state[i - 1].Rate_3_goldRatioPop; } else { state[i].Rate_3_goldRatioPop = i + 1; } } sort(state, state + N, comp0304);//奖牌人口比例 排名 和记录排名 for (int i = 0; i < N; ++i) { if (i == 0) { state[i].Rate_4_medalRationPop = i + 1; } else if (state[i].medalRationPop == state[i - 1].medalRationPop) { state[i].Rate_4_medalRationPop = state[i - 1].Rate_4_medalRationPop; } else { state[i].Rate_4_medalRationPop = i + 1; } } //测试和调解BUG //for (int i = 0; i < N; ++i) { // printf("%d %d %d %d %.2lf %.2f %d %d %d %d\n", state[i].aNum, state[i].goldMedal, state[i].medal, state[i].population, state[i].goldRatioPop, state[i].medalRationPop, // state[i].Rate_1_goldMedal, state[i].Rate_2_medal, state[i].Rate_3_goldRatioPop, state[i].Rate_4_medalRationPop); //} //按格式要求输出计算数据 for (int i = 0; i < M; ++i) { for (int j = 0; j < N; ++j) { if (arrM[i] == state[j].aNum) { if (state[j].Rate_1_goldMedal <= state[j].Rate_2_medal && state[j].Rate_1_goldMedal <= state[j].Rate_3_goldRatioPop && state[j].Rate_1_goldMedal <= state[j].Rate_4_medalRationPop) { printf("%d:1\n", state[j].Rate_1_goldMedal); } else if (state[j].Rate_2_medal <= state[j].Rate_3_goldRatioPop && state[j].Rate_2_medal <= state[j].Rate_4_medalRationPop) { printf("%d:2\n", state[j].Rate_2_medal); } else if (state[j].Rate_3_goldRatioPop <= state[j].Rate_4_medalRationPop) { printf("%d:3\n", state[j].Rate_3_goldRatioPop); } else { printf("%d:4\n", state[j].Rate_4_medalRationPop); } } } } } system("pause"); return EXIT_SUCCESS; } // 64 位输出请用 printf("%lld")