九度1007:奥运排序问题
来源:互联网 发布:重庆知联大厦二手房 编辑:程序博客网 时间:2024/04/28 07:57
- 题目描述:
按要求,给国家进行排名。
- 输入:
- 有多组数据。
第一行给出国家数N,要求排名的国家数M,国家号从0到N-1。
第二行开始的N行给定国家或地区的奥运金牌数,奖牌数,人口数(百万)。
接下来一行给出M个国家号。
- 输出:
- 排序有4种方式: 金牌总数 奖牌总数 金牌人口比例 奖牌人口比例
对每个国家给出最佳排名排名方式 和 最终排名
格式为: 排名:排名方式
如果有相同的最终排名,则输出排名方式最小的那种排名,对于排名方式,金牌总数 < 奖牌总数 < 金牌人口比例 < 奖牌人口比例
如果有并列排名的情况,即如果出现金牌总数为 100,90,90,80.则排名为1,2,2,4.
每组数据后加一个空行。
- 样例输入:
4 44 8 16 6 24 8 22 12 40 1 2 34 28 10 18 11 28 12 38 13 40 3
- 样例输出:
1:31:12:11:21:11:1
代码如下:
#include <iostream>using namespace std;int main(void){int N, M;while (cin >> N >> M){int *gold = new int[N];//分配内存int *goldnum = new int[N];int *population = new int[N];double *goldrate = new double[N];double *goldnumrate = new double[N];int *country = new int[M]; //输入for (int i = 0; i < N; i++){cin >> gold[i];cin >> goldnum[i];cin >> population[i];goldrate[i] = (double)gold[i] / (double)population[i];goldnumrate[i] = (double)goldnum[i] / (double)population[i];}for (int i = 0; i < M; i++){cin >> country[i];}//计算排名for (int i = 0; i < M; i++){int best = 0;int method = 0;int ranking[4] = { 1,1,1,1 };for (int j = 0; j < M; j++){if (gold[country[j]] > gold[country[i]])ranking[0]++;if (goldnum[country[j]] > goldnum[country[i]])ranking[1]++;if (goldrate[country[j]] > goldrate[country[i]])ranking[2]++;if (goldnumrate[country[j]] > goldnumrate[country[i]])ranking[3]++;}int min = 1000;for (int k = 0; k < 4; k++){if (ranking[k] < min){method = k + 1;best = ranking[k];min = ranking[k];}}cout << best << ":" << method << endl;}cout << endl;delete []gold;delete[]goldnum;delete[]goldrate;delete[]goldnumrate;delete[]country;}return 0;}
注意事项:
1、注意金牌人口比例(goldrate)和奖牌人口比例(goldnumrate)的类型为 double
2、本题是“排序问题” 最好将图画出来,容易分析。值得注意的是 本题的排名不是所有国家排名 是M个国家参与排名,所以在排名比较时,要写成
gold[country[j]] > gold[country[i]] 而不是gold[j]>gold[i]
3、因为开头 new分配了数组空间,所以最后要delete掉。
1 0
- 九度 1007 奥运排序问题
- 【九度】题目1007:奥运排序问题
- 九度OJ 1007 奥运排序问题
- 九度 题目1007:奥运排序问题
- 九度OJ--1007-奥运排序问题
- 九度OJ 1007 奥运排序问题
- 九度OJ-1007:奥运排序问题
- 九度1007:奥运排序问题
- 九度题目1007:奥运排序问题
- 九度[1007]-奥运排序问题
- 九度OJ 1007:奥运排序问题 (排序)
- 九度oj 题目1007:奥运排序问题
- 九度OJ 题目1007:奥运排序问题
- 九度OJ 题目1007:奥运排序问题
- 九度oj 题目1007:奥运排序问题
- hdu3789/九度OJ1007 奥运排序问题
- 九度:1007<排序><奥运排序>
- 九度oj 题目1007:奥运排序问题 【ZJU2010考研机试题3】【容易理解混乱】
- C#语言基础总结-2
- 补码、反码的相关问题
- [BZOJ 1036][ZJOI2008]树的统计Count(树链剖分)
- Error: Finish can only be called once
- 从零移植uboot 2017 到nuc970(第十六天)
- 九度1007:奥运排序问题
- Git使用教程
- HTTP返回码
- gibbs sampling
- jquery 监控键盘事件
- tcp_wraper——轻量级的iptables防火应用
- 括号问题
- NG机器学习第六周:关于模型的调优选择
- springview