第一行输入两个整数
,分别表示报名人数与计划录取人数。
接下来
行,每行输入两个整数
,分别为报名号与笔试成绩。报名号保证唯一。
第一行输出两个整数:面试分数线
与进入面试的人数
。
接下来
行,按排序顺序输出每位选手的报名号
与成绩
,每行两个整数,用空格分隔。
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;
}
}
#n1:报名人数 n2:计划录取人数
n1,n2 = list(map(int,input().split(" ")))
t = int(n2 * 1.5)
grades = {}
for i in range(n1):
k,s = list(map(int,input().split(" ")))
grades[k] = s
result = sorted(grades.items(),key=lambda x:(-1*x[1],x[0]))
line = result[t-1][1]
count = 0
result1 = []
for _,value in result:
if value >=line:
result1.append([_,value])
count +=1
print("{} {}".format(line,count))
for no,value in result1:
print('{} {}'.format(no,value)) while True:
try:
n, m = map(int, input().split()) # n:总人数, m:计划录取人数
info = {}
for _ in range(n):
idx, score = map(int, input().split())
info[idx] = score
# 按规则排序:成绩降序,成绩相同时报名号升序
sorted_items = sorted(info.items(), key=lambda x: (-x[1], x[0]))
# 计算面试名额(向下取整)
t = int(1.5 * m) # Python的int()对于正数就是向下取整
# 第t名选手的成绩就是面试分数线
# 注意:列表索引从0开始,所以第t名对应索引t-1
score_line = sorted_items[t - 1][1]
# 所有成绩不低于分数线的选手均进入面试
# 因为可能有多个同分选手,所以要用 >=
qualified = {k: v for k, v in sorted_items if v >= score_line}
# 输出结果
print(score_line, len(qualified))
for k, v in qualified.items():
print(k, v)
except:
break import java.util.Arrays;
import java.util.Scanner;
import java.util.TreeMap;
import java.util.TreeSet;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int m = in.nextInt();
int t = (int)(m * 1.5 ) ;
int[][] score = new int[n][2];
//存储所有人的分数
for (int i = 0; i < n; i++ ) {
score[i][0] = in.nextInt();
score[i][1] = in.nextInt();
}
// System.out.println(Arrays.toString(score));
int[] id = new int[n];
int[] po = new int[n];
//按分数排序分开存储
for (int j = 0; j < n; j++) {
int max = 0;
for (int i = 0; i < n; i++) {
max = Math.max(max, score[i][1]);
}
for (int i = 0; i < n; i++) {
if (score[i][1] == max) {
id[j] = score[i][0];
po[j] = score[i][1];
score[i][0] = 0;
score[i][1] = 0;
break;
}
}
// System.out.println(max);
}
// System.out.println(Arrays.toString(id));
// System.out.println(Arrays.toString(po));
//如果考号前大后小,交换顺序
for (int j = 0; j < n; j++) {
for (int i = 0; i < n - 1; i++) {
if (po[i] == po[i + 1] && id[i] > id[i + 1]) {
int temp = id[i];
id[i] = id[i + 1];
id[i + 1] = temp;
}
}
}
//计算分数线,这里一定要t-1,因为po的编号从0开始
int line = po[t-1];
//满足分数线的人计数
int count =0;
for(int i=0; i<n; i++){
if(po[i] >=line){
count++;
}
}
System.out.println(line+" "+count);
for (int i = 0; i < n; i++) {
if (po[i] >= line) {
System.out.println(id[i] + " " + po[i]);
}
}
}
} import java.util.*;
import java.io.*;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
String[] line1 = bf.readLine().split(" ");
int n = Integer.parseInt(line1[0]);
int m = Integer.parseInt(line1[1]);
ArrayList<Student> list = new ArrayList<>();
String line;
while ((line = bf.readLine()) != null) {
Student s = new Student(Integer.parseInt(line.split(" ")[0]),
Integer.parseInt(line.split(" ")[1]));
list.add(s);
}
list.sort(new Comparator<Student>() {
@Override
public int compare(Student o1, Student o2) {
int i = o2.score - o1.score;//分数从高到低
//如分数相同再按id排序(升序)
//如果i非0,直接用分数差的正负值排序
i = i == 0 ? o1.id - o2.id : i;
return i;
}
});
int en_num = (int)Math.floor(m *1.5); //实际进面人数由分数线决定,同分可进,大于en_num数
int en_sco = list.get(en_num - 1).score;
int count = 0;//统计分数
for (int i = 0; i < n; i++) {
if (list.get(i).score < en_sco) {
break;
}
count++;
}
// System.out.println(m);
System.out.println(en_sco + " " + count);
for (int i = 0; i < count; i++) {
System.out.println(list.get(i));
}
}
}
class Student {
int id;
int score;
public Student(int id, int score) {
this.id = id;
this.score = score;
}
@Override
public String toString() {
return id + " " + score;
}
} import java.util.*;
import java.util.stream.Collectors;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int m = in.nextInt();
int t = (int) Math.floor(1.5 * m);
List<Candidate> candidates = new ArrayList<>();
while (n-- > 0) {
int k = in.nextInt();
int s = in.nextInt();
Candidate candidate = new Candidate(k, s);
candidates.add(candidate);
}
List<Candidate> collect = candidates.stream().sorted(Comparator.comparing(Candidate::getScore).reversed().thenComparing(Candidate::getId))
.collect(Collectors.toList());
int score = collect.get(t - 1).getScore();
List<Candidate> collect1 = collect.stream().filter(c -> c.getScore() >= score).collect(Collectors.toList());
System.out.println(score + " " + collect1.size());
collect1.forEach(c -> System.out.println(c.getId() + " " + c.getScore()));
}
}
class Candidate {
int id;
int score;
public Candidate(int id, int score) {
this.id = id;
this.score = score;
}
public int getId() {
return id;
}
public int getScore() {
return score;
}
} package main
import (
"fmt"
"sort"
)
type Person struct {
Id int
Score int
}
func main() {
n := 0
m := 0
fmt.Scan(&n, &m)
bishi := []Person{}
scoreMap := map[int]int{}
for {
k, s := 0, 0
n, _ := fmt.Scan(&k, &s)
if n == 0 {
break
}
scoreMap[s]++
one := Person{k, s}
bishi = append(bishi, one)
}
mNum := m*3/2
// fmt.Println(n, m, bishi, mNum)
sort.Slice(bishi, func(i, j int) bool {
if bishi[i].Score > bishi[j].Score {
return true
} else if bishi[i].Score == bishi[j].Score {
return bishi[i].Id < bishi[j].Id
} else {
return false
}
})
minScore := bishi[mNum-1].Score
for i, v := range bishi {
if v.Score < minScore {
mNum = i
break
}
}
fmt.Println(minScore, mNum)
for _, v := range bishi {
if v.Score < minScore {
break
}
fmt.Println(v.Id, v.Score)
}
} import math
n,m=map(int,input().split())
c=[]
for _ in range(n):
a,b=map(int,input().split())
c.append([-b,a])#b.extend([a, b]) =[a,b],c.append([a,b])=[[a,b],]
c.sort()
for i in range(n):
if c[i][0]<=0:
c[i][0]=(-c[i][0])
d=math.floor(m*1.5) #m*1.5//1
f=c[d-1][0]
count =0
g=[]
for i in range(n):
if c[i][0]>=f:
count +=1
print(f"{f} {count}")
for i in range(count):
print(f"{c[i][1]} {c[i][0]}")