奥运排序问题(关键字排序)
来源:互联网 发布:算法设计与分析答案 编辑:程序博客网 时间:2024/06/06 07:24
Problem Link:点击打开链接
[编程题]奥运排序问题
题目描述
按要求,给国家进行排名。
输入描述:
有多组数据。第一行给出国家数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
AC code:
#include<iostream>#include<algorithm>#include<stdio.h>#include<string.h>#include<math.h>#include<queue>#include<set>#include<map>using namespace std;struct node{ double orderValue[4]; int order[4]; int num;}nation[1010];node na[1010];bool cmp0(node a,node b)//按国家编号从小到大排 { return a.num<b.num;}bool cmp1(node a,node b)//按金牌总数从大到小排 {return a.orderValue[0]>b.orderValue[0];}bool cmp2(node a,node b)//按奖牌总数从大到小排 {return a.orderValue[1]>b.orderValue[1];} bool cmp3(node a,node b)//按金牌人口比例从大到小排{return a.orderValue[2]>b.orderValue[2];}bool cmp4(node a,node b)//按奖牌人口比例从大到小排 {return a.orderValue[3]>b.orderValue[3];} int main(){//freopen("D:\\in.txt","r",stdin);//freopen("D:\\out.txt","w",stdout);int i,j,N,M,index;int gold,total,peo,num;while(scanf("%d%d",&N,&M)!=EOF){for(i=0;i<N;++i){scanf("%d%d%d",&gold,&total,&peo);nation[i].num=i;nation[i].orderValue[0]=gold;nation[i].orderValue[1]=total;nation[i].orderValue[2]=gold*1.0/peo;nation[i].orderValue[3]=total*1.0/peo;}for(i=0;i<M;++i){scanf("%d",&num);na[i]=nation[num];}sort(na,na+M,cmp1);na[0].order[0]=1;for(i=1;i<M;++i){if(na[i].orderValue[0]==na[i-1].orderValue[0])na[i].order[0]=na[i-1].order[0];elsena[i].order[0]=i+1;}sort(na,na+M,cmp2);na[0].order[1]=1;for(i=1;i<M;++i){if(na[i].orderValue[1]==na[i-1].orderValue[1])na[i].order[1]=na[i-1].order[1];elsena[i].order[1]=i+1;}sort(na,na+M,cmp3);na[0].order[2]=1;for(i=1;i<M;++i){if(na[i].orderValue[2]==na[i-1].orderValue[2])na[i].order[2]=na[i-1].order[2];elsena[i].order[2]=i+1;}sort(na,na+M,cmp4);na[0].order[3]=1;for(i=1;i<M;++i){if(na[i].orderValue[3]==na[i-1].orderValue[3])na[i].order[3]=na[i-1].order[3];elsena[i].order[3]=i+1;}sort(na,na+M,cmp0);for(i=0;i<M;++i){index=0;for(j=1;j<4;++j){if(na[i].order[j]<na[i].order[index])index=j;}printf("%d:%d\n",na[i].order[index],index+1);}puts("");}return 0; }
0 0
- 奥运排序问题(关键字排序)
- 1007.奥运排序问题
- 1007 奥运排序问题
- 奥运排序问题
- 九度OJ 1007:奥运排序问题 (排序)
- 题目1007:奥运排序问题
- 题目1007:奥运排序问题
- hdu 3789 奥运排序问题
- 题目1007:奥运排序问题
- 题目1007:奥运排序问题
- 题目1007:奥运排序问题
- 题目1007:奥运排序问题
- 题目1007:奥运排序问题
- hdoj 3789 奥运排序问题
- hdoj 3789 奥运排序问题
- hdu 3789 奥运排序问题
- 题目1007:奥运排序问题
- 题目1007:奥运排序问题
- sublime Text 正则替换
- AFNetworking之UIKit扩展与缓存实现
- FZU 2105 Digits Count
- 嵌入式数据库(八)
- 第四天(Linux环境配置与搭建和java环境配置)
- 奥运排序问题(关键字排序)
- py-faster-rcnn配置运行demo.py(Ubuntu14.04),不成功的朋友请与我(lee)联系,后面附带邮箱
- 驱动级,socks5 代理 支持udp tcp
- java之核心问题大作战
- CLASSPATH 是什麼
- Centos6.8从源码安装Gitlab详细教程
- 用正则表达式获取网页里面的内容/java面试题
- LeetCode 108Convert Sorted Array to Binary Search Tree
- BZOJ3626: [LNOI2014]LCA LCT