第一行输入两个整数
,分别表示报名人数与计划录取人数。
接下来
行,每行输入两个整数
,分别为报名号与笔试成绩。报名号保证唯一。
第一行输出两个整数:面试分数线
与进入面试的人数
。
接下来
行,按排序顺序输出每位选手的报名号
与成绩
,每行两个整数,用空格分隔。
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;
}
}
#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]}") 代码有点拉跨,胜在便于理解
#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]);
}
}
}
}