|
https://oj.singera.cn/dist/quesInfo?problem_id=1107
根据题目描述,我们可以得出以下结论:
解题步骤:
1.从高到低排序
2.算出分数线
3.输出得分不低于分数线的人
--如何求解分数线?
m*150% = m*1.5
首先
要给所有分数进行排序
然后
算出m*1.5向下取整
找到排名m*1.5的分数即可
这里采用冒泡排序来解题
要注意分数相同时需要比较编号
- #include<iostream>
- #include<string.h>
- using namespace std;
- struct person{
- int id;
- int score;
- }one[5000];
- int main(){
- int n,m,i,j,t,k,d;
- cin>>n>>m;
- int count = 0;
- for (i=0;i<n;i++)
- {
- cin>>one[i].id>>one[i].score;
- }
- for (i=0;i<n-1;i++)
- {
- for (j=i+1;j<n;j++)
- {
- if (one[i].score<one[j].score)
- {
- swap(one[i],one[j]);
- }
- if (one[i].score==one[j].score)
- {
- if (one[i].id>one[j].id)
- {
- swap(one[i],one[j]);
- }
- }
- }
- }
- d = int(m*1.5);
- k = one[d-1].score;
- for (i=0;i<n;i++)
- {
- if (one[i].score>=k)
- {
- count++;
- }
- }
- cout<<k<<" "<<count<<endl;
- for (i=0;i<count;i++)
- {
- cout<<one[i].id<<" "<<one[i].score<<endl;
- }
- return 0;
- }
复制代码
|
|