九度OJ 1007 奥运排序问题
来源:互联网 发布:windows 会员如何加入 编辑:程序博客网 时间:2024/04/28 04:28
- 题目描述:
按要求,给国家进行排名。
- 输入:
- 有多组数据。
第一行给出国家数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 <stdio.h>#include <algorithm>using namespace std;struct COUNTRY{double num_g, num_m, popu;double r_g, r_m;int rank[5];int ID;}country[200],buf[200];bool cmp1(COUNTRY a, COUNTRY b){return a.num_g > b.num_g;} // 按金牌总数排序bool cmp2(COUNTRY a, COUNTRY b){return a.num_m > b.num_m;} // 按奖牌总数排序bool cmp3(COUNTRY a, COUNTRY b){return a.r_g > b.r_g;} // 按金牌人口比例排序bool cmp4(COUNTRY a, COUNTRY b){return a.r_m > b.r_m;} // 按奖牌人口比例排序bool cmp5(COUNTRY a, COUNTRY b){return a.ID < b.ID;} // 最后再按ID排序int main(){int N, M;while(scanf("%d%d",&N,&M) != EOF){int i,j;for(i = 0; i < N; i++){scanf("%lf%lf%lf",&buf[i].num_g,&buf[i].num_m,&buf[i].popu);buf[i].r_g = buf[i].num_g / buf[i].popu;buf[i].r_m = buf[i].num_m / buf[i].popu;for(j = 0; j < 5; j++)buf[i].rank[j] = 0;buf[i].ID = i;}int input_M, top = -1;for(i = 0; i < M; i++){scanf("%d",&input_M);country[++top] = buf[input_M];} // 注意只需对要求排序的M个国家排序sort(country,country+M,cmp1);for(i = 0; i < N; i++){if(i == 0)country[i].rank[1] = 1;else{if(country[i].num_g == country[i-1].num_g)country[i].rank[1] = country[i-1].rank[1];elsecountry[i].rank[1] = i + 1;}} // 确定按第一种方式排序的名次sort(country,country+M,cmp2);for(i = 0; i < N; i++){if(i == 0)country[i].rank[2] = 1;else{if(country[i].num_m == country[i-1].num_m)country[i].rank[2] = country[i-1].rank[2];elsecountry[i].rank[2] = i + 1;}} // 确定按第二种方式排序的名次sort(country,country+M,cmp3);for(i = 0; i < N; i++){if(i == 0)country[i].rank[3] = 1;else{if(country[i].r_g == country[i-1].r_g)country[i].rank[3] = country[i-1].rank[3];elsecountry[i].rank[3] = i + 1;}} // 确定按第三种方式排序的名次sort(country,country+M,cmp4);for(i = 0; i < N; i++){if(i == 0)country[i].rank[4] = 1;else{if(country[i].r_m == country[i-1].r_m)country[i].rank[4] = country[i-1].rank[4];elsecountry[i].rank[4] = i + 1;}} // 确定按第四种方式排序的名次sort(country,country+M,cmp5); // 再将各国按ID从小到大排序for(i = 0; i < M; i++){int min = N, rank_min;for(j = 1; j < 5; j++)if(country[i].rank[j] < min){min = country[i].rank[j];rank_min = j;} //找出最佳排序结果和排序方式printf("%d:%d\n",min,rank_min);}printf("\n"); //题目要求每组数据后加一个空行}return 0;}
0 0
- 九度OJ 1007 奥运排序问题
- 九度OJ--1007-奥运排序问题
- 九度OJ 1007 奥运排序问题
- 九度OJ-1007:奥运排序问题
- 九度OJ 1007:奥运排序问题 (排序)
- 九度oj 题目1007:奥运排序问题
- 九度OJ 题目1007:奥运排序问题
- 九度OJ 题目1007:奥运排序问题
- 九度oj 题目1007:奥运排序问题
- 九度 1007 奥运排序问题
- 【九度】题目1007:奥运排序问题
- 九度 题目1007:奥运排序问题
- 九度1007:奥运排序问题
- 九度题目1007:奥运排序问题
- 九度[1007]-奥运排序问题
- 九度oj 题目1007:奥运排序问题 【ZJU2010考研机试题3】【容易理解混乱】
- 九度oj 题目1007:奥运排序问题(但无法通过)
- hdu3789/九度OJ1007 奥运排序问题
- python过滤html 标签
- java调用CICS服务遇到的错误及解决方法
- hdu1255 矩形面积二次交
- 机器人破解注册原理
- 本地通知
- 九度OJ 1007 奥运排序问题
- ARM全新Cortex-A17定位中端,主频2G
- Java 7之多线程第8篇 - 互斥锁 ReentrantLock
- c# dataset保存多属性的XML
- linux iptables
- 程序员如何快速准备面试中的算法
- GDB 调试
- 练习,打豆豆
- AutoMapper使用简单总结