首页 > 试题广场 >

奥运排序问题

[编程题]奥运排序问题
  • 热度指数:14431 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 64M,其他语言128M
  • 算法知识视频讲解
按要求,给国家进行排名。

输入描述:
有多组数据。
第一行给出国家数N,要求排名的国家数M,国家号从0到N-1。
第二行开始的N行给定国家或地区的奥运金牌数,奖牌数,人口数(百万)。
接下来一行给出M个国家号。


输出描述:
排序有4种方式: 金牌总数 奖牌总数 金牌人口比例 奖牌人口比例 
对每个国家给出最佳排名排名方式 和 最终排名
格式为: 排名:排名方式
如果有相同的最终排名,则输出排名方式最小的那种排名,对于排名方式,金牌总数 < 奖牌总数 < 金牌人口比例 < 奖牌人口比例 
如果有并列排名的情况,即如果出现金牌总数为 100,90,90,80.则排名为1,2,2,4.
每组数据后加一个空行。
示例1

输入

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


头像 wbc990512
发表于 2021-01-26 17:10:32
一开始还在思考怎么排序,怎么用结构体还有qsort。。。看到讨论区大佬(肆年)的算法,拨云见雾,原来不需要排序就可以做了,只需要遍历一遍,如果发现其他国家该排名比自己好那就给自己排名加1。 #include <stdio.h> #define N 10 int main() { 展开全文
头像 GMRCCC
发表于 2022-02-10 13:51:10
用结构体排序也能做,只是稍微麻烦一些,对每种排名方式均要进行一次排序 #include <iostream> #include<algorithm> #include<malloc.h> using namespace std; st 展开全文
头像 Huster水仙
发表于 2023-01-04 22:12:35
/*思想不难,排名不用排序,有国家指标比你高,你的排名就++ 很坑的是对于输入人口为0的处理:奖牌为0,比率也为0;奖牌不为0,比率无穷大 */ #include<iostream> #include<limits> using namespace std; 展开全文
头像 渺小小螃蟹
发表于 2021-05-09 21:54:25
//学不会的程序 #include <stdio.h> #define N 233 //截止到2021年,全世界有233个国家和地区 int main() { int n,m; while(scanf("%d%d",&n,&m)!=EOF) //国家 展开全文
头像 牛客419094931号
发表于 2022-02-12 17:14:12
这道题有个天坑: 输入数据中人口可能是0。多组数据的人口是0,金牌人口比、奖牌人口比都是并列第一,比如8.3.0和6.5.0金牌人口比和奖牌人口比都是并列第一。而输入数据还有0.3.0这样式的,题目认为这种的金牌人口比是0,倒数第一。 #include <iostream> #inclu 展开全文
头像 DioDid
发表于 2022-01-21 12:53:01
在做题过程中 要注意: 比率是按照浮点数形式表示的 #include <stdio.h> #include <stdlib.h> typedef struct Nation { int GoldMedalNum; int MedalNum; int 展开全文
头像 牛客202753268号
发表于 2023-02-20 18:07:05
#include <cfloat> #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> #include<math.h> #include<algorithm& 展开全文
头像 Perceive109
发表于 2023-01-16 14:40:47
// // Created by xxx on 2023/1/16. // #include "iostream" using namespace std; class country_117 { public: int gold; // 金牌数 int medal; // 展开全文
头像 窝在小角落里刷题
发表于 2023-01-17 20:13:34
#include <iostream> #include <cstdio> #include <algorithm> using namespace std; /* * 国家 */ struct Country { int goldMedal; 展开全文
头像 loveC--
发表于 2024-02-24 22:08:47
用结构体加sort花了4个小时,机试考这种题我直接暴毙而亡 #include<iostream> #include<algorithm> using namespace std; typedef struct Country { int gold; int pedal; 展开全文