团体天梯练习 L2-027 名人堂与代金券
L2-027 名人堂与代金券
对于在中国大学MOOC(http://www.icourse163.org/ )学习“数据结构”课程的学生,想要获得一张合格证书,总评成绩必须达到
输入格式:
输入在第一行给出 3 个整数,分别是
输出格式:
首先在一行中输出发出的
输入样例:
10 80 5
cy@zju.edu.cn 78
cy@pat-edu.com 87
1001@qq.com 65
uh-oh@163.com 96
test@126.com 39
anyone@qq.com 87
zoe@mit.edu 80
jack@ucla.edu 88
bob@cmu.edu 80
ken@163.com 70
输出样例:
360
1 uh-oh@163.com 96
2 jack@ucla.edu 88
3 anyone@qq.com 87
3 cy@pat-edu.com 87
5 bob@cmu.edu 80
5 zoe@mit.edu 80
解题思路
模拟题。稍微有点难度的地方在于题中给出了名人堂的最底名次,并且存在并列,这就需要记录上一次所用到的排名编号以及此排名编号的人数。
/* 一切都是命运石之门的选择 El Psy Kongroo */
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<cmath>
#include<functional>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<double, double> pdd;
typedef pair<string, int> psi;
typedef __int128 int128;
#define PI acos(-1.0)
#define x first
#define y second
//int dx[4] = {1, -1, 0, 0};
//int dy[4] = {0, 0, 1, -1};
const int inf = 0x3f3f3f3f, mod = 1e9 + 7;
const int N = 10010;
int n, g, k;
vector<psi> p; //存储人的姓名 分数
int sum; //总代金券
int id[N]; //记录排名
int main(){
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> g >> k;
while(n -- ){
psi cur; cin >> cur.x >> cur.y;
if(cur.y >= 60 && cur.y < g) sum += 20;
else if(cur.y >= g && cur.y <= 100) sum += 50;
p.push_back(cur);
}
cout << sum << endl;
sort(p.begin(), p.end(), [](psi &a, psi &b){
if(a.y != b.y) return a.y > b.y;
return a.x < b.x;
});
int pre = p[0].y, pre_id = 1, cnt = 0; //记录上一次用到的分数及排名 记录处于此排名的人数
id[0] = 1;
for(int i = 1; ; i ++ ){
if(p[i].y == pre) id[i] = pre_id, cnt ++ ; //并列
else if(p[i].y < pre) id[i] = pre_id += cnt + 1, cnt = 0;
pre = p[i].y;
if(pre_id > k) break;
}
for(int i = 0; id[i] <= k && id[i]; i ++ )
cout << id[i] << ' ' << p[i].x << ' ' << p[i].y << endl;
return 0;
}
一切都是命运石之门的选择,本文章来源于博客园,作者:MarisaMagic,出处:https://www.cnblogs.com/MarisaMagic/p/17332429.html,未经允许严禁转载
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具