洛谷 P1068 [NOIP2009 普及组] 分数线划定
心得:没什么可说,结构体排序,so easy
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 1e4;
int scoreLine;//分数线
int realNum; //实际人数
struct node{ //选手
int id;//报名号
int score;//笔试成绩
}player[N];
bool cmp(struct node s1, struct node s2){ //结构体排序规则 照笔试成绩从高到低输出,如果成绩相同,则按报名号由小到大的顺序输出
if(s1.score != s2.score) return s1.score > s2.score ;
else return s1.id < s2.id ;
}
class FindScore{ //一元谓词 查找所有选手中分数大于分数线的人数
public:
bool operator()(struct node s){
return s.score >= scoreLine;
}
};
int main(){
int m,n;
cin >> n >> m;
for(int i = 0; i < n; i++){
cin >> player[i].id >> player[i].score ;
}
sort(player,player+n,cmp); //排序
realNum = m*150/100; //按题意 保证实际人数至少为这些
scoreLine = player[realNum - 1].score ; //录取分数线
int num = count_if(player,player+n,FindScore()); //查找分数大于等于录取分数线的实际人数
realNum = num;
cout << scoreLine << " " << realNum << endl;
for(int i = 0; i < realNum; i++){
cout << player[i].id << " "<< player[i].score << endl;
}
return 0;
}