跳到正文

题解

P13797 [SWERC 2023] Programming-trampoline-athlon! 题解

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

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 2 分钟
题目
P13797

版本

  1. v2当前
  2. v1

蒟蒻的第一篇题解。。。

什么意思? QAQ

输入一个团队在本次比赛中的得分信息和名称,求前三名,并输出团队名称和总分。

怎么做? OvO

很显然,这需要使用struct结构体储存信息。

C++
struct TEAM{
	string c;//团队名称
	int score,id;//团队总分,团队id
}t[100010];

我只存储了一些重要数据。

接着呢,还需要一个排序函数。

C++
bool comp(TEAM x,TEAM y){
    if(x.score!=y.score) return x.score>y.score;
    //先比较比分score,从大到小排序
    return x.id<y.id;
    //若比分相同,则比较输入顺序id,从小到大排序
}

输入很简单,然后是输出

C++
  for(int i=1; i<=n; i++){
  		if(i>1 && t[i].score!=t[i-1].score) o=i;
      //可能有多个团队的得分相同
    	if(o>3) break;//保证有前三名
    	cout<<t[i].c<<" "<<t[i].score<<endl;//输出
	}

代码代码 O.O

C++
#include <bits/stdc++.h>//万能头文件
using namespace std;//解决重名问题

struct TEAM{
	string c;
	int score,id;
}t[100010];

bool comp(TEAM x,TEAM y){
    if(x.score!=y.score) return x.score>y.score;
    return x.id<y.id;
}

int n,m,o=1,e[10],p;

int main(){
	cin>>n;
	for(int i=1; i<=n; i++){
		cin>>t[i].c>>p;
		t[i].id=i;
		for(int j=1; j<=6; j++)cin>>e[j];
		sort(e+1,e+7);
		t[i].score=e[2]+e[3]+e[4]+e[5]+p*10;
	}
	sort(t+1,t+n+1,comp);
	for(int i=1; i<=n; i++){
		if(i>1 && t[i].score!=t[i-1].score) o=i;
    	if(o>3) break;
    	cout<<t[i].c<<" "<<t[i].score<<endl;
	}
	return 0;
  //qLoLq
}

调了很久才AC。。。

原文