跳到正文

题解

题解:P11185 奖牌排序

wangboyue_740325约 2 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月28日
篇幅
约 2 分钟
获赞
1
题目
P11185

版本

  1. v1当前

思路

对每种奖牌数量排序后,对每个小朋友,二分在每种奖牌中的最后出现位置位置即可。 例如:样例,第 33 个小朋友情况如下:(数组为排序后)

代码
g: 2 4 4 8
s: 1 1 5 5
b: 0 1 2 3

在金牌中,出现位置为 33,排名为 n−3+1=2n-3+1=2。 在银牌中,出现位置为 22,排名为 n−2+1=3n-2+1=3。 在铜牌中,出现位置为 33,排名为 n−3+1=2n-3+1=2。 最前排名为 min⁡(2,3,2)=2\min(2,3,2)=2。

代码

C++
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int N=2e5+5;
int n,g[N],s[N],b[N],sg[N],ss[N],sb[N];
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>g[i]>>s[i]>>b[i];
		sg[i]=g[i];
		ss[i]=s[i];
		sb[i]=b[i];
	}
	sort(sg+1,sg+1+n);
	sort(ss+1,ss+1+n);
	sort(sb+1,sb+1+n);
	for(int i=1;i<=n;i++){
		cout<<min({n-(upper_bound(sg+1,sg+1+n,g[i])-sg-1)+1,
		n-(upper_bound(ss+1,ss+1+n,s[i])-ss-1)+1,
		n-(upper_bound(sb+1,sb+1+n,b[i])-sb-1)+1})<<endl;
	}
	return 0;
}
原文