第一行输入两个整数
,分别表示报名人数与计划录取人数。
接下来
行,每行输入两个整数
,分别为报名号与笔试成绩。报名号保证唯一。
第一行输出两个整数:面试分数线
与进入面试的人数
。
接下来
行,按排序顺序输出每位选手的报名号
与成绩
,每行两个整数,用空格分隔。
6 3 9848 90 6731 88 1422 95 7483 84 8805 95 4162 88
88 5 1422 95 8805 95 9848 90 4162 88 6731 88
计算:,第
名成绩为
,故分数线
;所有
的共有
人。
class Interviewee:
def __init__(self,id:int,score:int):
self.id = id
self.score = score
def __repr__(self):
return f'{self.id} {self.score}'
def main():
n,m = map(int,input().split())
t = int(m * 1.5)
interviewees = []
for _ in range(n):
id,score = map(int,input().split())
interviewees.append(Interviewee(id,score))
interviewees_sorted = sorted(interviewees,key = lambda x : (-x.score,x.id))
targe_score = interviewees_sorted[t-1].score
selected = []
cur_index = 0
while interviewees_sorted[cur_index].score >= targe_score:
selected.append(interviewees_sorted[cur_index])
cur_index += 1
print(f'{selected[-1].score} {len(selected)}')
for interviewee in selected:
print(interviewee)
if __name__ == '__main__':
main() import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int m = scanner.nextInt();
int t = (int) (m * 1.5);
List<Candidate> candidates = new ArrayList<>();
for (int i = 0; i < n; i++) {
int k = scanner.nextInt();
int s = scanner.nextInt();
candidates.add(new Candidate(k, s));
}
// 排序:成绩从高到低,成绩相同报名号从小到大
// Override Comparator比较器
candidates.sort((o1, o2)-> {
if (o1.score != o2.score) return o2.score - o1.score;
else return o1.id - o2.id;
});
int line = candidates.get(t - 1).score;
int cnt = 0;
List<Candidate> interviewCandidates = new ArrayList<>();
for (Candidate candidate : candidates) {
if (candidate.score >= line) {
interviewCandidates.add(candidate);
cnt++;
}
}
System.out.println(line + " " + cnt);
for (Candidate candidate : interviewCandidates) {
System.out.println(candidate.id + " " + candidate.score);
}
scanner.close();
}
}
class Candidate {
int id;
int score;
public Candidate(int id, int score) {
this.id = id;
this.score = score;
}
} 这里主要是学习sort自定义排序算法。
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
int main() {
int n,m;
cin>>n>>m;
int t=floor(m*1.5);
vector<pair<int,int>> v(n);
while (n--) {
int k,s;
cin>>k>>s;
v.push_back({k,s});
}
sort(v.begin(), v.end(),[](const auto& a ,const auto & b){
return a.second==b.second?a.first<b.first:a.second>b.second;
});
int lines=v[t-1].second;
int ci=0;
for(int i=0;i<v.size();i++){
if(v[i].second>=lines){
ci++;
}
}
cout<<lines<<" "<<ci<<endl;
for(int i=0;i<ci;i++){
cout<<v[i].first<<" "<<v[i].second<<endl;
}
}
from math import floor m,n = map(int,input().split()) res = [] for _ in range(m): i,score = map(int,input().split()) res.append((score,i)) res.sort(key= lambda x:(-x[0],x[1])) t = floor(1.5*n) line = res[t-1][0] for j in range(t,len(res)): if res[j][0]==line: t+=1 print(line,t) for j in range(t): print(res[j][1],res[j][0])
#include <bits/stdc++.h>
using namespace std;
int main() {
int n,m;cin>>n>>m;
int t=floor(1.5*m);
auto cmp=[](const pair<int,int>& a,const pair<int,int>& b){
if(a.first!=b.first) return a.first>b.first;
return a.second<b.second;
};
multiset<pair<int,int>,decltype(cmp)>num(cmp);
while(n--){
int k,s;cin>>k>>s;
num.insert({s,k});
}
int cnt=0,line=0;
for(auto it=num.begin();it!=num.end();it++){
cnt++;
if(cnt==t){
line=it->first;
auto next_it=it;
next_it++;
while(next_it!=num.end()&&next_it->first==line){
cnt++;
next_it++;
}
break;
}
}
cout<<line<<' '<<cnt<<endl;
int i=0;
for(auto it=num.begin();it!=num.end()&&i<cnt;it++,i++){
cout<<it->second<<' '<<it->first<<endl;
}
} package main
import (
"fmt"
"sort"
)
func main() {
n := 0
m := 0
fmt.Scan(&n, &m)
persons := make([][2]int, n)
for i := 0; i < n; i++ {
fmt.Scan(&persons[i][0], &persons[i][1])
}
sort.Slice(persons, func(i, j int) bool {
if persons[i][1] == persons[j][1] {
return persons[i][0] < persons[j][0] // 小到大
}
return persons[i][1] > persons[j][1] // 高到低
})
t := int(float64(m) * 15 / 10)
if t > len(persons) {
t = len(persons)
} else {
for t < len(persons) {
if persons[t-1][1] == persons[t][1] {
t = t + 1
} else {
break
}
}
}
line := persons[t-1][1]
fmt.Printf("%v %v\n", line, t)
for i := 0; i < t; i++ {
fmt.Printf("%v %v\n", persons[i][0], persons[i][1])
}
} using System;
using System.Collections.Generic;
public class Program {
public static void Main() {//算法非常经典的入门题
//刚学acm时都会做
//此题考验 自定义sort的考察,大概无论什么语言都能自定义sort
string line;
line = System.Console.ReadLine();
string[] parts =line.Split( );
int n = int.Parse(parts[0]);
int m = int.Parse(parts[1]);
int t =(int )(1.5*m);
List<person> lis = new List<person>();
for(int i=0;i<n;++i){
parts=System.Console.ReadLine().Split( );
lis.Add(new person(int.Parse(parts[0]) ,int.Parse( parts[1]) ));
}
lis.Sort( (a,b)=>{
int cmp = b.score.CompareTo(a.score);
//cmp 只有三种植 -1 0 1
//在sort返回值中 -1代表着 a在前面 0不变 1 a在后面
//在c# 中 应该所有简单类型都内置了 CompareTo
//所以a.CompareTo(b) 是升序 反过来是降序
return cmp ==0? a.name.CompareTo(b.name) : cmp;
} );
int innum=0;
int inscore = lis[t-1].score;
for(int i=0;i<n;++i){
if(lis[i].score >= inscore){
innum ++;
}
}
Console.WriteLine(inscore +" " +innum);
for(int i=0;i<innum;++i){
Console.WriteLine(lis[i].name + " "+lis[i] .score );
}
}
public class person{
public int score;
public int name;
public person( int n,int s ){
name= n;
score =s;
}
}
} #include <iostream>
using namespace std;
#include<vector>
#include<algorithm>
class Student{
public:
Student(int id,int grade){
this->mid=id;
this->mgrade=grade;
}
int mid;
int mgrade;
};
class mysort{
public:
bool operator()(Student s1,Student s2){
if(s1.mgrade==s2.mgrade){
return s1.mid<s2.mid;
}
return s1.mgrade>s2.mgrade;
}
};
int main() {
int m,n;
cin>>n>>m;
vector<Student>v;
while(n--){
int k,s;
cin>>k>>s;
Student stu(k,s);
v.push_back(stu);
}
sort(v.begin(),v.end(),mysort());
double t=m*1.5;
t=int(t);
int t_grade=v[t-1].mgrade;
// cout<<t<<endl;
cout<<t_grade<<" ";
int joinnumber=0;
for_each(v.begin(),v.end(),[&](Student s){
if(s.mgrade>=t_grade){
joinnumber++;
}
});
cout<<joinnumber<<endl;
for(int i=0;i<joinnumber;i++){
cout<<v[i].mid<<" "<<v[i].mgrade<<endl;
}
}
// 64 位输出请用 printf("%lld") #include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n, m;
while (cin >> n >> m) {
vector<pair<int, int>> infor(n);
int k, s;//k 是 报名号,s 是笔试成绩
for (int i = 0; i < n; ++i) {
cin >> k >> s;
infor.emplace_back(k,
s);//直接在容器的内存空间里 “就地” 创建元素,省去拷贝 / 移动的开销。
}
sort(infor.begin(), infor.end(), [](const auto & a, const auto & b) {
return a.second == b.second ? a.first<b.first: a.second>b.second;
}); //按第二列降序排序,若第二列值相等,按第一列升序
int num = floor(m * 1.5);
int score_line = infor[num - 1].second;
int cnt = 0;
for (auto& i : infor) {
if (i.second >= score_line)
++cnt;
}
cout << score_line << " " << cnt << endl;
for (int j = 0; j < cnt; ++j) {
cout << infor[j].first << " " << infor[j].second << endl;
}
}
return 0;
}
n,m=map(int,input().split(' '));aa=[];fs=[];t=int(1.5*m)
for i in range(n):
a,b=map(int,input().split(' '))
aa.append((a,b));fs.append(b)
aa.sort(key=lambda t:(-t[1],t[0]))
if t>=n:
li_ne=min(fs);cnt=n
else:
li_ne=aa[t-1][1];cnt=sum(list(1 for x in fs if x >= li_ne))
print(li_ne,cnt)
for i in range(cnt):
print(aa[i][0],aa[i][1]) import math
# 定义两个整数分别表示报名人数与计划录取人数
n,m = map(int,input().split())
# 定义一个字典,用于存储笔试者序号及笔试成绩
dict_score = {}
# 进行笔试人序号及成绩的输入
for _ in range(n):
k,s = map(int,input().split())
dict_score[k] = s
tuple_score = sorted(dict_score.items(), key=lambda x: (-x[1], x[0]))
# print(tuple_score)
t = math.floor(1.5 * m)
x = tuple_score[t-1][1]
count = 0
for j in dict_score.values():
if j >= x:
count+=1
print(f"{x} {count}")
for i in range(n):
if tuple_score[i][1] >= x:
print(f"{tuple_score[i][0]} {tuple_score[i][1]}") 代码有点拉跨,胜在便于理解