洛谷P1068 分数线划定

https://www.luogu.org/problem/P1068

#include<bits/stdc++.h>
using namespace std;
struct Can {
int num;
int score;
} can[];
bool compare1(Can a, Can b) {
return a.score > b.score;
}
bool compare2(Can a, Can b) {
return a.num < b.num;
}
int n, m;
int mline, mscore;
int head = , tail = , mid;
int main() {
cin >> n >> m;
for (int i = ; i < n; i++)
cin >> can[i].num >> can[i].score;
sort(can, can + n, compare1); //按成绩排序 从大到小
mline = floor(1.5*m); //floor取不大于x的最大整数 人数
mscore = can[mline - ].score; //面试成绩 因为从0开始的,所以要减一
for (int i = floor(1.5*m); i < n; i++) //查看往后是否存在相同的成绩
if (can[i].score == mscore) //如果存在,加一
mline++; //计算面试总人数
mid = can[].score;
for (int i = ; i <= mline; i++) {
if (can[i].score != mid) { //判断成绩是否相同
sort(can + head, can + tail + head, compare2); //如果没有相同的,相当于给自己排序
head = head + tail; //排头相加
tail = ; //如果重新开始,要重新定义的。
mid = can[head].score; //重新定义排头
} else tail++; //当相同的时候,tail++,然后给相同的按编号排序
}
cout << mscore << " " << mline << endl;
for (int i = ; i < mline; i++)
cout << can[i].num << " " << can[i].score << endl;
return ;
}
上一篇:用turtle实现动态汉诺塔


下一篇:JSTL Tag学习笔记(一)之