PAT 1015 德才论
https://pintia.cn/problem-sets/994805260223102976/problems/994805307551629312
宋代史学家司马光在《资治通鉴》中有一段著名的“德才论”:“是故才德全尽谓之圣人,才德兼亡谓之愚人,德胜才谓之君子,才胜德谓之小人。凡取人之术,苟不得圣人,君子而与之,与其得小人,不若得愚人。”
现给出一批考生的德才分数,请根据司马光的理论给出录取排名。
输入格式:
输入第一行给出 3 个正整数,分别为:N(≤),即考生总数;L(≥),为录取最低分数线,即德分和才分均不低于 L 的考生才有资格被考虑录取;H(<),为优先录取线——德分和才分均不低于此线的被定义为“才德全尽”,此类考生按德才总分从高到低排序;才分不到但德分到线的一类考生属于“德胜才”,也按总分排序,但排在第一类考生之后;德才分均低于 H,但是德分不低于才分的考生属于“才德兼亡”但尚有“德胜才”者,按总分排序,但排在第二类考生之后;其他达到最低线 L 的考生也按总分排序,但排在第三类考生之后。
随后 N 行,每行给出一位考生的信息,包括:准考证号 德分 才分,其中准考证号为 8 位整数,德才分为区间 [0, 100] 内的整数。数字间以空格分隔。
输出格式:
输出第一行首先给出达到最低分数线的考生人数 M,随后 M 行,每行按照输入格式输出一位考生的信息,考生按输入中说明的规则从高到低排序。当某类考生中有多人总分相同时,按其德分降序排列;若德分也并列,则按准考证号的升序输出。
输入样例:
14 60 80
10000001 64 90
10000002 90 60
10000011 85 80
10000003 85 80
10000004 80 85
10000005 82 77
10000006 83 76
10000007 90 78
10000008 75 79
10000009 59 90
10000010 88 45
10000012 80 100
10000013 90 99
10000014 66 60
输出样例:
12
10000013 90 99
10000012 80 100
10000003 85 80
10000011 85 80
10000004 80 85
10000007 90 78
10000006 83 76
10000005 82 77
10000002 90 60
10000014 66 60
10000008 75 79
10000001 64 90
时间复杂度:$O(N * logN)$
代码1:
#include <bits/stdc++.h>
using namespace std; const int maxn = 1e5 + 10;
int N, L, H;
int cnt = 0; struct Students {
char num[10];
int D;
int C;
int score;
int type;
}s[maxn]; bool cmp(const Students& a, const Students& b) {
if(a.type != b.type) return a.type < b.type;
if(a.score != b.score) return a.score > b.score;
if(a.D != b.D) return a.D > b.D;
return strcmp(a.num, b.num) < 0;
} void GetStudentType(int d, int c, int& type) {
if(d < L || c < L) {
type = 5;
} else {
if(d >= H && c >= H) type = 1;
else if(d >= H && c < H) type = 2;
else if(d < H && c < H && d >= c) type = 3;
else type = 4;
}
} int main() {
scanf("%d%d%d", &N, &L, &H);
for(int i = 1; i <= N; i ++) {
scanf("%s%d%d", s[i].num, &s[i].D, &s[i].C);
GetStudentType(s[i].D, s[i].C, s[i].type);
s[i].score = s[i].D + s[i].C;
if(s[i].type != 5) cnt ++;
} sort(s + 1, s + 1 + N, cmp);
printf("%d\n", cnt);
for(int i = 1; i <= N; i ++) {
if(s[i].type != 5)
printf("%s %d %d\n", s[i].num, s[i].D, s[i].C);
}
return 0;
}
死亡代码:
#include <bits/stdc++.h>
using namespace std; const int maxn = 1e5 + 10;
int N, L, H; struct Students {
char num[10];
int D;
int C;
int score;
}students[maxn]; struct Node1 {
char num11[10];
int D1;
int C1;
int score1;
}node1[maxn]; struct Node2 {
char num22[10];
int D2;
int C2;
int score2;
}node2[maxn]; struct Node3 {
char num33[10];
int D3;
int C3;
int score3;
}node3[maxn]; struct Node4 {
char num44[10];
int D4;
int C4;
int score4;
}node4[maxn]; bool cmp1(const Node1& a, const Node1& b) {
if(a.score1 != b.score1)
return a.score1 < b.score1;
else {
if(a.D1 != b.D1)
return a.D1 < b.D1;
else
return strcmp(a.num11, b.num11) > 0;
}
} bool cmp2(const Node2& c, const Node2& d) {
if(c.score2 != d.score2)
return c.score2 < d.score2;
else {
if(c.D2 != d.D2)
return c.D2 < d.D2;
else
return strcmp(c.num22, d.num22) > 0;
}
} bool cmp3(const Node3& e, const Node3& f) {
if(e.score3 != f.score3)
return e.score3 < f.score3;
else {
if(e.D3 != f.D3)
return e.D3 < f.D3;
else
return strcmp(e.num33, f.num33) > 0;
}
} bool cmp4(const Node4& aa, const Node4& ab) {
if(aa.score4 != ab.score4)
return aa.score4 < ab.score4;
else {
if(aa.D4 != ab.D4)
return aa.D4 < ab.D4;
else
return strcmp(aa.num44, ab.num44) > 0;
}
} int main() {
scanf("%d%d%d", &N, &L, &H);
for(int i = 1; i <= N; i ++) {
scanf("%s%d%d", students[i].num, &students[i].D, &students[i].C);
} int num1 = 0, num2 = 0, num3 = 0, num4 = 0;
for(int i = 1; i <= N; i ++) {
if(students[i].C < L || students[i].D < L) {
continue;
}
else {
if(students[i].C >= H && students[i].D >= H) {
num1 ++;
strcpy(node1[num1].num11, students[i].num);
node1[num1].C1 = students[i].C;
node1[num1].D1 = students[i].D;
node1[num1].score1 = students[i].C + students[i].D;
}
else if(students[i].D >= H && students[i].C < H) {
num2 ++;
strcpy(node2[num2].num22, students[i].num);
node2[num2].C2 = students[i].C;
node2[num2].D2 = students[i].D;
node2[num2].score2 = students[i].C + students[i].D;
}
else if(students[i].D < H && students[i].C < H && students[i].D >= students[i].C) {
num3 ++;
strcpy(node3[num3].num33, students[i].num);
node3[num3].C3 = students[i].C;
node3[num3].D3 = students[i].D;
node3[num3].score3 = students[i].C + students[i].D;
}
else {
num4 ++;
strcpy(node4[num4].num44, students[i].num);
node4[num4].C4 = students[i].C;
node4[num4].D4 = students[i].D;
node4[num4].score4 = students[i].C + students[i].D;
}
}
} sort(node1 + 1, node1 + num1 + 1, cmp1);
sort(node2 + 1, node2 + num2 + 1, cmp2);
sort(node3 + 1, node3 + num3 + 1, cmp3);
sort(node4 + 1, node4 + num4 + 1, cmp4); printf("%d\n", num1 + num2 + num3 + num4);
//printf("%d %d %d\n", num1, num2, num3);
for(int i = num1; i >= 1; i --)
printf("%s %d %d\n", node1[i].num11, node1[i].D1, node1[i].C1);
for(int i = num2; i >= 1; i --)
printf("%s %d %d\n", node2[i].num22, node2[i].D2, node2[i].C2);
for(int i = num3; i >= 1; i --)
printf("%s %d %d\n", node3[i].num33, node3[i].D3, node3[i].C3);
for(int i = num4; i >= 1; i --)
printf("%s %d %d\n", node4[i].num44, node4[i].D4, node4[i].C4);
return 0;
}
PAT 1015 德才论的更多相关文章
- PAT 1015 德才论 (25)(代码+思路)
1015 德才论 (25)(25 分)提问 宋代史学家司马光在<资治通鉴>中有一段著名的"德才论":"是故才德全尽谓之圣人,才德兼亡谓之愚人,德胜才谓之君子, ...
- PAT——1015. 德才论
宋代史学家司马光在<资治通鉴>中有一段著名的“德才论”:“是故才德全尽谓之圣人,才德兼亡谓之愚人,德胜才谓之君子,才胜德谓之小人.凡取人之术,苟不得圣人,君子而与之,与其得小人,不若得愚人 ...
- PAT 1015. 德才论 (25) JAVA
宋代史学家司马光在<资治通鉴>中有一段著名的"德才论":"是故才德全尽谓之圣人,才德兼亡谓之愚人,德胜才谓之君子,才胜德谓之小人.凡取人之术,苟不得圣人,君子 ...
- PAT 1015. 德才论 (25)
宋代史学家司马光在<资治通鉴>中有一段著名的"德才论":"是故才德全尽谓之圣人,才德兼亡谓之愚人,德胜才谓之君子,才胜德谓之小人.凡取人之术,苟不得圣人,君子 ...
- PAT(B)1015 德才论(C)
题目链接:1015 德才论 (25 point(s)) 分析 由题意可知,需要将考生按照分数进行一个分类(级),然后在每一级中按照分数排序.输入的时候将每个人的总分,等级和录取人数先算出来.然后按照自 ...
- PAT乙级 1015. 德才论 (25)
1015. 德才论 (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Li 宋代史学家司马光在<资治通鉴&g ...
- 【PAT】1015 德才论 (25)(25 分)
1015 德才论 (25)(25 分) 宋代史学家司马光在<资治通鉴>中有一段著名的“德才论”:“是故才德全尽谓之圣人,才德兼亡谓之愚人,德胜才谓之君子,才胜德谓之小人.凡取人之术,苟不得 ...
- pat 乙级 1015. 德才论 (25) c++
http://39.106.25.239 个人网站 欢迎访问 交流 1015. 德才论 (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Sta ...
- PAT乙级:1015 德才论 (25分)
1015 德才论 (25分) 宋代史学家司马光在<资治通鉴>中有一段著名的"德才论":"是故才德全尽谓之圣人,才德兼亡谓之愚人,德胜才谓之君子,才胜德谓之小人 ...
随机推荐
- SP1043 GSS1 - Can you answer these queries I(线段树,区间最大子段和(静态))
题目描述 给出了序列A[1],A[2],…,A[N]. (a[i]≤15007,1≤N≤50000).查询定义如下: 查询(x,y)=max{a[i]+a[i+1]+...+a[j]:x≤i≤j≤y} ...
- [USACO08NOV]时间管理Time Management(排序,贪心)
题目描述 作为一名忙碌的商人,约翰知道必须高效地安排他的时间.他有N工作要 做,比如给奶牛挤奶,清洗牛棚,修理栅栏之类的. 为了高效,列出了所有工作的清单.第i分工作需要T_i单位的时间来完成,而 且 ...
- EpiiAdmin 开源的php交互性管理后台框架, 让复杂的交互变得更简单!Phper快速搭建交互性平台的开发框架,基于Thinkphp5.1+Adminlte3.0+Require.js。
EpiiAdmin EpiiAdmin php开源交互性管理后台框架,基于Thinkphp5.1+Adminlte3.0+Require.js, 让复杂的交互变得更简单!Phper快速搭建交互性平台的 ...
- 【Hive二】 Hive基本使用
Hive基本使用 创建数据库 创建一个数据库,数据库在HDFS上的默认存储路径是/user/hive/warehouse/*.db create database 库名; 避免要创建的数据库已经存在错 ...
- CRC校验8
什么是CRC校验? CRC即循环冗余校验码:是数据通信领域中最常用的一种查错校验码,其特征是信息字段和校验字段的长度可以任意选定.循环冗余检查(CRC)是一种数据传输检错功能,对数据进行多项式计算,并 ...
- 解决如下出错:DeprecationWarning: Passing 1d arrays as data is deprecated in 0.17 and willraise ValueError in 0.19.
背景:在Spyder中写几行脚本,目的是应用sklearn自带的svm(支持向量机)算法,来对其自带的digits(手写体数字)数据集进行分类,过程包括训练阶段和预测阶段.将手写体数字数据的特征数据d ...
- (数据科学学习手札36)tensorflow实现MLP
一.简介 我们在前面的数据科学学习手札34中也介绍过,作为最典型的神经网络,多层感知机(MLP)结构简单且规则,并且在隐层设计的足够完善时,可以拟合任意连续函数,而除了利用前面介绍的sklearn.n ...
- hdu 1394 Minimum Inversion Number(线段树)
参考:http://blog.sina.com.cn/s/blog_691ce2b70101ldmm.html https://blog.csdn.net/wiking__acm/article/de ...
- js字符串操作函数
js字符串函数 JS自带函数 concat 将两个或多个字符的文本组合起来,返回一个新的字符串. var a = "hello"; var b = ",world&quo ...
- 安装一个apk文件源代码
/** * 安装一个apk文件 * * @param file * 要安装的完整文件名 */ protected void installApk(File file) { ...