题目1007:奥运排序问题

本文深入探讨了信息技术领域的核心技术和应用,包括但不限于前端开发、后端开发、移动开发、游戏开发、大数据开发等细分领域。文章详细阐述了各技术的原理、实践案例以及最新发展趋势,旨在为读者提供全面的技术洞察和应用指导。

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

题目描述:

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

输入:
有多组数据。
第一行给出国家数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 <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
using namespace std;

struct Country{
	int no,g,t,p,method;
	int rank[4]; 
};

bool cmpbyno(Country a,Country b){
	return a.no < b.no;
}
bool cmpbyg(Country a,Country b){
		return a.g > b.g;
}
bool cmpbyt(Country a,Country b){
	return a.t > b.t;
}
bool cmpbygp(Country a,Country b){
	return a.g * b.p > a.p * b.g;
}
bool cmpbytp(Country a,Country b){
	return a.t * b.p > b.t * a.p;
}

int min(int a,int b){
	return a < b ? a: b;
}
Country c1[1000],c2[1000];
int main()
{
	int n,m,num;
	while(cin >> n >> m){
		for(int i = 0;i < n;i++)
			scanf("%d %d %d",&c1[i].g,&c1[i].t,&c1[i].p);
		for(int i = 0;i < m;i++){
			 scanf("%d",&num);
			 c2[i].no = i;
			 c2[i].g = c1[num].g;
			 c2[i].t = c1[num].t;
			 c2[i].p = c1[num].p;
		}

		sort(c2,c2 + m,cmpbyg);
		c2[0].rank[0] = 1;
		c2[0].method = 1;
		for(int i = 1;i < m;i++){
			 if(c2[i].g == c2[i - 1].g)
				 c2[i].rank[0] = c2[i - 1].rank[0];
			 else
				 c2[i].rank[0] = i + 1;
			 c2[i].method = 1;
		}

		sort(c2,c2 + m,cmpbyt);
	    c2[0].rank[1] = 1;
		for(int i = 1;i < m;i++){
			if(c2[i].t == c2[i - 1].t)
				 c2[i].rank[1] = c2[i - 1].rank[1];
			else
				 c2[i].rank[1] = i + 1;
		}

		sort(c2,c2 + m,cmpbygp);
	    c2[0].rank[2] = 1;
		for(int i = 1;i < m;i++){
			int rank;
			if(c2[i].g * c2[i - 1].p == c2[i].p * c2[i - 1].g)
				 c2[i].rank[2] = c2[i - 1].rank[2];
			else
				 c2[i].rank[2] = i + 1;
		}

		sort(c2,c2 + m,cmpbytp);
		c2[0].rank[3] = 1;
		for(int i = 1;i < m;i++){
			if(c2[i].t * c2[i - 1].p == c2[i].p * c2[i - 1].t)
				c2[i].rank[3] = c2[i - 1].rank[3];
			else
				 c2[i].rank[3] = i + 1;
		}
		for(int i = 0;i < m;i++)
			for(int k = 1;k < 4;k++)
			{
				if(c2[i].rank[k] < c2[i].rank[0]){
					c2[i].rank[0] = c2[i].rank[k];
				    c2[i].method = k + 1;
				}
			}

		sort(c2,c2 + m,cmpbyno);
		for(int i = 0;i < m;i++)
		  cout << c2[i].rank[0] << ":" << c2[i].method << endl;
		cout << endl;
	}
	return 1;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值