PAT (Advanced Level) Practise 1062 Talent and Virtue (25)

xiaoxiao2021-02-28  20

1062. Talent and Virtue (25)

时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Li

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_Grade where 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 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 Sample Output: 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

题意:给出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 long const 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("d %d %d\n",a[i].id,a[i].s1,a[i].s2); for(int i=0;i<cnt2;i++) printf("d %d %d\n",b[i].id,b[i].s1,b[i].s2); for(int i=0;i<cnt3;i++) printf("d %d %d\n",c[i].id,c[i].s1,c[i].s2); for(int i=0;i<cnt4;i++) printf("d %d %d\n",d[i].id,d[i].s1,d[i].s2); } return 0; }

1062. Talent and Virtue (25)

时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Li

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_Grade where 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 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 Sample Output: 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

题意:给出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 long const 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("d %d %d\n",a[i].id,a[i].s1,a[i].s2); for(int i=0;i<cnt2;i++) printf("d %d %d\n",b[i].id,b[i].s1,b[i].s2); for(int i=0;i<cnt3;i++) printf("d %d %d\n",c[i].id,c[i].s1,c[i].s2); for(int i=0;i<cnt4;i++) printf("d %d %d\n",d[i].id,d[i].s1,d[i].s2); } return 0; }

PAT (Advanced Level) Practise 1062 Talent and Virtue (25)

转载请注明原文地址: https://www.6miu.com/read-46528.html

最新回复(0)