'commit'
This commit is contained in:
43
TangDou/CSP-J/AcWingTraining/T2/438.cpp
Normal file
43
TangDou/CSP-J/AcWingTraining/T2/438.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
|
||||
const int N = 5010;
|
||||
/*
|
||||
先将所有同学按分数高者优先、序号小者优先进行双关键字排序。
|
||||
|
||||
然后求出分数线:即排名在 ⌊1.5m⌋ 的同学的分数。
|
||||
|
||||
最后找出成绩大于等于分数线的同学人数。
|
||||
*/
|
||||
int n, m;
|
||||
|
||||
struct Person {
|
||||
int id, score;
|
||||
|
||||
} person[N];
|
||||
|
||||
bool cmp(Person a, Person b) {
|
||||
if (a.score != b.score) return a.score > b.score;
|
||||
return a.id < b.id;
|
||||
}
|
||||
|
||||
int main() {
|
||||
cin >> n >> m;
|
||||
|
||||
for (int i = 0; i < n; i++)
|
||||
cin >> person[i].id >> person[i].score;
|
||||
sort(person, person + n, cmp);
|
||||
|
||||
int k = m * 1.5;
|
||||
// 一样分数的也要入围
|
||||
while (k < n && person[k - 1].score == person[k].score) k++;
|
||||
|
||||
// 输出入围分数和入围人数
|
||||
printf("%d %d\n", person[k - 1].score, k);
|
||||
|
||||
// 输出入围人数ID及分数
|
||||
for (int i = 0; i < k; i++)
|
||||
printf("%d %d\n", person[i].id, person[i].score);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user