PAT (Advanced Level) Practise 1062 Talent and Virtue (25)
来源:互联网 发布:查询域名是否已备案 编辑:程序博客网 时间:2024/05/22 20:35
1062. Talent and Virtue (25)
About 900 years ago, a Chinese philosopher Sima Guang wrote a history book in which he talked about people's talent and virtue. According to his theory, a man being outstanding in both talent and virtue must be a "sage(圣人)"; being less excellent but with one's virtue outweighs talent can be called a "nobleman(君子)"; being good in neither is a "fool man(愚人)"; yet a fool man is better than a "small man(小人)" who prefers talent than virtue.
Now given the grades of talent and virtue of a group of people, you are supposed to rank them according to Sima Guang's theory.
Input Specification:
Each input file contains one test case. Each case first gives 3 positive integers in a line: N (<=105), the total number of people to be ranked; L (>=60), the lower bound of the qualified grades -- that is, only the ones whose grades of talent and virtue are both not below this line will be ranked; and H (<100), the higher line of qualification -- that is, those with both grades not below this line are considered as the "sages", and will be ranked in non-increasing order according to their total grades. Those with talent grades below H but virtue grades not are cosidered as the "noblemen", and are also ranked in non-increasing order according to their total grades, but they are listed after the "sages". Those with both grades below H, but with virtue not lower than talent are considered as the "fool men". They are ranked in the same way but after the "noblemen". The rest of people whose grades both pass the L line are ranked after the "fool men".
Then N lines follow, each gives the information of a person in the format:
ID_Number Virtue_Grade Talent_Gradewhere ID_Number is an 8-digit number, and both grades are integers in [0, 100]. All the numbers are separated by a space.
Output Specification:
The first line of output must give M (<=N), the total number of people that are actually ranked. Then M lines follow, each gives the information of a person in the same format as the input, according to the ranking rules. If there is a tie of the total grade, they must be ranked with respect to their virtue grades in non-increasing order. If there is still a tie, then output in increasing order of their ID's.
Sample Input:14 60 8010000001 64 9010000002 90 6010000011 85 8010000003 85 8010000004 80 8510000005 82 7710000006 83 7610000007 90 7810000008 75 7910000009 59 9010000010 88 4510000012 80 10010000013 90 9910000014 66 60Sample Output:
1210000013 90 9910000012 80 10010000003 85 8010000011 85 8010000004 80 8510000007 90 7810000006 83 7610000005 82 7710000002 90 6010000014 66 6010000008 75 7910000001 64 90
题意:给出n个人的id,德分和才分,给出两个标准分l、h,德分或才分低于l的不排序,德分和才分都大于等于h的为第一类,德分大于等于h,才分低于h的为第二类,德分和才分都低于h,德分大于才分的为第三类,其余的为第四类。按第一类到第四类输出,同一类中总分高的在前面,总分相同的则德分高的在前面,德分相同则按id排序
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <algorithm>#include <queue>#include <stack>#include <cmath>#include <map>#include <bitset>#include <set>#include <vector>#include <functional>using namespace std;#define LL long longconst int INF = 0x3f3f3f3f;struct node{ int id,s1,s2,sum; friend bool operator <(node a,node b) { if(a.sum!=b.sum) return a.sum>b.sum; else if(a.s1!=b.s1) return a.s1>b.s1; else return a.id<b.id; }}x[100006],a[100006],b[100006],c[100006],d[100006];int main(){ int n,l,h; while(~scanf("%d%d%d",&n,&l,&h)) { int cnt1=0,cnt2=0,cnt3=0,cnt4=0; for(int i=1;i<=n;i++) { scanf("%d%d%d",&x[i].id,&x[i].s1,&x[i].s2); x[i].sum=x[i].s1+x[i].s2; if(x[i].s1<l||x[i].s2<l) continue; if(x[i].s1>=h&&x[i].s2>=h) a[cnt1++]=x[i]; else if(x[i].s1>=h) b[cnt2++]=x[i]; else if(x[i].s1<h&&x[i].s2<h&&x[i].s1>=x[i].s2) c[cnt3++]=x[i]; else d[cnt4++]=x[i]; } sort(a,a+cnt1); sort(b,b+cnt2); sort(c,c+cnt3); sort(d,d+cnt4); printf("%d\n",cnt1+cnt2+cnt3+cnt4); for(int i=0;i<cnt1;i++) printf("%08d %d %d\n",a[i].id,a[i].s1,a[i].s2); for(int i=0;i<cnt2;i++) printf("%08d %d %d\n",b[i].id,b[i].s1,b[i].s2); for(int i=0;i<cnt3;i++) printf("%08d %d %d\n",c[i].id,c[i].s1,c[i].s2); for(int i=0;i<cnt4;i++) printf("%08d %d %d\n",d[i].id,d[i].s1,d[i].s2); } return 0;}
1062. Talent and Virtue (25)
About 900 years ago, a Chinese philosopher Sima Guang wrote a history book in which he talked about people's talent and virtue. According to his theory, a man being outstanding in both talent and virtue must be a "sage(圣人)"; being less excellent but with one's virtue outweighs talent can be called a "nobleman(君子)"; being good in neither is a "fool man(愚人)"; yet a fool man is better than a "small man(小人)" who prefers talent than virtue.
Now given the grades of talent and virtue of a group of people, you are supposed to rank them according to Sima Guang's theory.
Input Specification:
Each input file contains one test case. Each case first gives 3 positive integers in a line: N (<=105), the total number of people to be ranked; L (>=60), the lower bound of the qualified grades -- that is, only the ones whose grades of talent and virtue are both not below this line will be ranked; and H (<100), the higher line of qualification -- that is, those with both grades not below this line are considered as the "sages", and will be ranked in non-increasing order according to their total grades. Those with talent grades below H but virtue grades not are cosidered as the "noblemen", and are also ranked in non-increasing order according to their total grades, but they are listed after the "sages". Those with both grades below H, but with virtue not lower than talent are considered as the "fool men". They are ranked in the same way but after the "noblemen". The rest of people whose grades both pass the L line are ranked after the "fool men".
Then N lines follow, each gives the information of a person in the format:
ID_Number Virtue_Grade Talent_Gradewhere ID_Number is an 8-digit number, and both grades are integers in [0, 100]. All the numbers are separated by a space.
Output Specification:
The first line of output must give M (<=N), the total number of people that are actually ranked. Then M lines follow, each gives the information of a person in the same format as the input, according to the ranking rules. If there is a tie of the total grade, they must be ranked with respect to their virtue grades in non-increasing order. If there is still a tie, then output in increasing order of their ID's.
Sample Input:14 60 8010000001 64 9010000002 90 6010000011 85 8010000003 85 8010000004 80 8510000005 82 7710000006 83 7610000007 90 7810000008 75 7910000009 59 9010000010 88 4510000012 80 10010000013 90 9910000014 66 60Sample Output:
1210000013 90 9910000012 80 10010000003 85 8010000011 85 8010000004 80 8510000007 90 7810000006 83 7610000005 82 7710000002 90 6010000014 66 6010000008 75 7910000001 64 90
题意:给出n个人的id,德分和才分,给出两个标准分l、h,德分或才分低于l的不排序,德分和才分都大于等于h的为第一类,德分大于等于h,才分低于h的为第二类,德分和才分都低于h,德分大于才分的为第二类,其余的为第四类。按第一类到第四类输出,同一类中总分高的在前面,总分相同的则德分高的在前面,德分相同则按id排序
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <algorithm>#include <queue>#include <stack>#include <cmath>#include <map>#include <bitset>#include <set>#include <vector>#include <functional>using namespace std;#define LL long longconst int INF = 0x3f3f3f3f;struct node{ int id,s1,s2,sum; friend bool operator <(node a,node b) { if(a.sum!=b.sum) return a.sum>b.sum; else if(a.s1!=b.s1) return a.s1>b.s1; else return a.id<b.id; }}x[100006],a[100006],b[100006],c[100006],d[100006];int main(){ int n,l,h; while(~scanf("%d%d%d",&n,&l,&h)) { int cnt1=0,cnt2=0,cnt3=0,cnt4=0; for(int i=1;i<=n;i++) { scanf("%d%d%d",&x[i].id,&x[i].s1,&x[i].s2); x[i].sum=x[i].s1+x[i].s2; if(x[i].s1<l||x[i].s2<l) continue; if(x[i].s1>=h&&x[i].s2>=h) a[cnt1++]=x[i]; else if(x[i].s1>=h) b[cnt2++]=x[i]; else if(x[i].s1<h&&x[i].s2<h&&x[i].s1>=x[i].s2) c[cnt3++]=x[i]; else d[cnt4++]=x[i]; } sort(a,a+cnt1); sort(b,b+cnt2); sort(c,c+cnt3); sort(d,d+cnt4); printf("%d\n",cnt1+cnt2+cnt3+cnt4); for(int i=0;i<cnt1;i++) printf("%08d %d %d\n",a[i].id,a[i].s1,a[i].s2); for(int i=0;i<cnt2;i++) printf("%08d %d %d\n",b[i].id,b[i].s1,b[i].s2); for(int i=0;i<cnt3;i++) printf("%08d %d %d\n",c[i].id,c[i].s1,c[i].s2); for(int i=0;i<cnt4;i++) printf("%08d %d %d\n",d[i].id,d[i].s1,d[i].s2); } return 0;}
PAT (Advanced Level) Practise 1062 Talent and Virtue (25)
- PAT (Advanced Level) Practise 1062 Talent and Virtue (25)
- PAT (Advanced Level) Practise 1062 Talent and Virtue (25)
- 1062. Talent and Virtue (25)【排序】——PAT (Advanced Level) Practise
- Pat(Advanced Level)Practice--1062(Talent and Virtue)
- 【C++】PAT (advanced level)1062. Talent and Virtue (25)
- 【PAT】【Advanced Level】1062. Talent and Virtue (25)
- PAT (Advanced) 1062. Talent and Virtue (25)
- PAT (Advanced Level) 1062. Talent and Virtue (25) 德才论,结构体排序
- PAT-Talent and Virtue (25)
- 1062. Talent and Virtue (25)-PAT
- pat 1062. Talent and Virtue (25)
- 【PAT】1062. Talent and Virtue (25)
- PAT A 1062. Talent and Virtue (25)
- PAT 1062. Talent and Virtue (25)
- 【PAT甲级】1062. Talent and Virtue (25)
- PAT---A1062. Talent and Virtue (25)
- PAT A1062. Talent and Virtue (25)
- PAT A1062. Talent and Virtue (25)
- Windows下Qt调用C++命令行程序——参数传递、字符编码转换
- 数据中的缺失值处理
- HOG特征显示 可视化HOG
- Debian 修改网络配置
- MAC电脑----webpack新手入门项目--图文教程
- PAT (Advanced Level) Practise 1062 Talent and Virtue (25)
- UVALIVE 3026 Period(kmp)
- 显式意图和隐式意图
- 算法-直接插入排序
- andoroid_ActionBar_遇见的错误
- vs2003在win7+后pdb锁住报LNK1201解决方案
- linux-011文件系统超级块的操作函数(挂载卸载系统)解析
- 文本摘要
- java 调试技能之 dubbo 调试 — telnet