跳到正文

题解

题解:AT_highrate2025_a 全完しないと出られない部屋

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

文章信息

收录
2025年12月15日
更新
2025年12月16日
篇幅
约 2 分钟

版本

  1. v1当前

题目思路

首先我们不难发现题目有两种排序顺序,优先级是完成时间 >> 预赛排名,所以我们可以用到结构体排序。

实现思路

首先我们要用一个结构体来存储时间和预赛的排名。

时间:

代码
a[i].t=s*m+e;//m道题每一道s秒,最后加上说的时间

排名:

代码
a[i].w=i;//因为我们是循环输入的所以i就是排名

那么我们存储了排名和时间后该如何来排序呢?

诶,这里就要用到对于新手来说较为好用的 sortsort 了。

我们在 sortsort 里面可以用一个函数来自定义排序的规则,这里就可以用到结构体的排序上了。

C++
bool cmp(no x,no y){
    if(x.t != y.t) return x.t > y.t;//时间不一样的话快的在前面
    return x.w < y.w;//时间相同的话就以预赛排名为准
}

代码实现

C++
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;
const int N=1e8+10;
struct no{
	long long w;
  long long t;//不开longlong会见祖宗的哦
};
no a[N];
ll n,m,s,e;
bool cmp(no x,no y){
    if(x.t != y.t) return x.t > y.t;
    return x.w < y.w;
}
int main(){
    ios::sync_with_stdio(false);
	  cin.tie(0);cout.tie(0);
    cin >> n >> m;
    for(int i=1;i<=n;i++){
        cin>>s>>e;
        a[i].t=s*m+e;//统计总时间
        a[i].w=i;//这就是预赛的排名
    }
    sort(a+1,a+n+1,cmp);//用到了上文中讲的结构体排序
    for(int i=1;i<=n;i++){
      cout<<a[i].w<<' ';
    }
	return 0;
}

求过qwq

原文