题目1007:奥运排序问题

本文针对奥运排序问题,提出了一种算法来对不同国家的奥运成绩进行综合排名。该算法考虑了金牌总数、奖牌总数、金牌人口比例和奖牌人口比例四个维度,并实现了对特定国家的最佳排名方式和最终排名的计算。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目1007:奥运排序问题

时间限制:1 秒

内存限制:32 兆

特殊判题:

提交:9411

解决:2033

参考:http://blog.youkuaiyun.com/sjf0115/article/details/8631735题目描述:

按要求,给国家进行排名。

输入:
有多组数据。
第一行给出国家数N,要求排名的国家数M,国家号从0到N-1。
第二行开始的N行给定国家或地区的奥运金牌数,奖牌数,人口数(百万)。
接下来一行给出M个国家号。
输出:
排序有4种方式: 金牌总数 奖牌总数 金牌人口比例 奖牌人口比例 
对每个国家给出最佳排名排名方式 和 最终排名
格式为: 排名:排名方式
如果有相同的最终排名,则输出排名方式最小的那种排名,对于排名方式,金牌总数 < 奖牌总数 < 金牌人口比例 < 奖牌人口比例 
如果有并列排名的情况,即如果出现金牌总数为 100,90,90,80.则排名为1,2,2,4.
每组数据后加一个空行。
样例输入:
4 4
4 8 1
6 6 2
4 8 2
2 12 4
0 1 2 3
4 2
8 10 1
8 11 2
8 12 3
8 13 4
0 3
样例输出:
1:3
1:1
2:1
1:2

1:1
1:1
#include <stdio.h>
#include <iostream>
#include <stack>
#include <string.h>
#include <queue>
#include <cmath>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <string>
using namespace std;
typedef long long LL;
 
struct Country
{
    int GoldNum;//金牌数
    int MedalNum;//奖牌数
    int PeopleNum;//人口数
    double GoldRatio;//金牌比例
    double MedalRatio;//奖牌比例
    int SKind;//最佳排名类型
    int BestRank;//最佳排名
    int Rank;//当前排名
};
Country country[1000];
int main() {
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int N, M, i, j, ID;
    Country countrySort[1001];
    while(scanf("%d %d", &N, &M) != EOF) {
        //给定国家或地区的奥运金牌数,奖牌数,人口数(百万)。
        for(int i = 0; i < N; i++){
            scanf("%d %d %d",&country[i].GoldNum,&country[i].MedalNum,&country[i].PeopleNum);
            country[i].GoldRatio = country[i].GoldNum * 1.0 / country[i].PeopleNum;
            country[i].MedalRatio = country[i].MedalNum * 1.0 / country[i].PeopleNum;
        }
        //给出要排序的M个国家号。
        for(i = 0;i < M;i++){
            scanf("%d",&ID);
            countrySort[i] = country[ID];
        }
 
        //分别按四种排序方式 进行排序 比较其最适合的
        for(i = 0;i < M;i++){
            //金牌数排序
            countrySort[i].Rank = 1;
            for(j = 0;j < M;j++){
                if(countrySort[i].GoldNum < countrySort[j].GoldNum){
                    countrySort[i].Rank++;
                }
            }
            countrySort[i].BestRank = countrySort[i].Rank;
            //printf("J:%d\n",countrySort[i].BestRank);
            countrySort[i].SKind = 1;
 
 
            //奖牌数排序
            countrySort[i].Rank = 1;
            for(j = 0;j < N;j++){
                if(countrySort[i].MedalNum < countrySort[j].MedalNum){
                    countrySort[i].Rank++;
                }
            }
            if(countrySort[i].Rank < countrySort[i].BestRank){
                countrySort[i].BestRank = countrySort[i].Rank;
                countrySort[i].SKind = 2;
            }
            //printf("J2:%d\n",countrySort[i].Rank);
 
 
            //金牌人口比例排序
            countrySort[i].Rank = 1;
            for(j = 0;j < N;j++){
                if(countrySort[i].GoldRatio < countrySort[j].GoldRatio){
                    countrySort[i].Rank++;
                }
            }
            if(countrySort[i].Rank < countrySort[i].BestRank){
                countrySort[i].BestRank = countrySort[i].Rank;
                countrySort[i].SKind = 3;
            }
            //printf("J3:%d\n",countrySort[i].Rank);
 
 
            //奖牌人口比例排序
            countrySort[i].Rank = 1;
            for(j = 0;j < N;j++){
                if(countrySort[i].MedalRatio < countrySort[j].MedalRatio){
                    countrySort[i].Rank++;
                }
            }
            if(countrySort[i].Rank < countrySort[i].BestRank){
                countrySort[i].BestRank = countrySort[i].Rank;
                countrySort[i].SKind = 4;
            }
            //printf("J4:%d\n",countrySort[i].Rank);
            //输出
            printf("%d:%d\n",countrySort[i].BestRank,countrySort[i].SKind);
        }
        //每组数据后加一个空行。
        printf("\n");
    }//while
    return 0;
}
 
 
/**************************************************************
    Problem: 1007
    User: Crazy_man
    Language: C++
    Result: Accepted
    Time:0 ms
    Memory:1564 kb
****************************************************************/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值