返回

1062. Talent and Virtue (25)

发布时间:2022-11-30 09:09:58 346

1062. Talent and Virtue (25)_struct


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久,用直接一个sort 段错误,内存过大或者超时。跟着别人的代码改写,还是改了n久。cout会超时啊


2015-7-21舍友用了一个sort的没有超时,然后我就试着把改了一下。单个sort 可以了


评测结果

时间

结果

得分

题目

语言

用时(ms)

内存(kB)

用户

7月21日 12:01

答案正确

​​25​​

​​1062​​

​​C++ (g++ 4.7.2)​​

58

3820

​​datrilla​​

测试点

测试点

结果

用时(ms)

内存(kB)

得分/满分

0

答案正确

1

308

12/12

1

答案正确

1

308

2/2

2

答案正确

28

692

3/3

3

答案正确

57

3820

3/3

4

答案正确

58

3636

3/3

5

答案正确

1

180

2/2

#include 
#include
using namespace std;
struct TalentandVirtue
{
int ID_Number;
int Virtue_Grade, Talent_Grade, sum;
int character;
};
bool TVcompare(const TalentandVirtue &front, const TalentandVirtue &behind)
{
if (front.character == behind.character)
{
if (front.sum > behind.sum)
return true;
else if (front.sum == behind.sum&&front.Virtue_Grade > behind.Virtue_Grade)
return true;
else if (front.sum == behind.sum&&front.Virtue_Grade == behind.Virtue_Grade&&front.ID_Number < behind.ID_Number)
return true;
}
else if(front.character > behind.character)return true;
return false;
}
int main()
{
TalentandVirtue *TV;
int N, inc, L, H, add;
scanf("%d%d%d",&N,&L,&H);
TV = (TalentandVirtue*)malloc(sizeof(TalentandVirtue)*N);
for (inc = 0, add = 0; add < N; add++)
{
scanf("%d%d%d",&TV[inc].ID_Number,&TV[inc].Virtue_Grade ,&TV[inc].Talent_Grade);
TV[inc].sum = TV[inc].Virtue_Grade + TV[inc].Talent_Grade;

if (TV[inc].Virtue_Grade < L || TV[inc].Talent_Grade < L);
else
{
if (TV[inc].Virtue_Grade >= H&&TV[inc].Talent_Grade >= H)
TV[inc].character = 4;
else if (TV[inc].Virtue_Grade >= H)
TV[inc].character = 3;
else if (TV[inc].Virtue_Grade < H&&TV[inc].Talent_Grade < H&&TV[inc].Virtue_Grade >= TV[inc].Talent_Grade)
TV[inc].character = 2;
else TV[inc].character = 1;
inc++;
}
}
printf("%d\n",inc);
sort(TV,TV+inc, TVcompare);
for (add= 0; add printf("%08d %d %d\n", TV[add].ID_Number, TV[add].Virtue_Grade, TV[add].Talent_Grade);
free(TV);
return 0;
}

评测结果

时间

结果

得分

题目

语言

用时(ms)

内存(kB)

用户

7月17日 19:48

答案正确

​​25​​

​​1062​​

​​C++ (g++ 4.7.2)​​

112

3556

​​datrilla​​

测试点

测试点

结果

用时(ms)

内存(kB)

得分/满分

0

答案正确

1

244

12/12

1

答案正确

1

236

2/2

2

答案正确

82

720

3/3

3

答案正确

112

3556

3/3

4

答案正确

112

3488

3/3

5

答案正确

1

256

2/2


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
struct TalentandVirtue
{
int ID_Number;
int Virtue_Grade,Talent_Grade,sum;
} ;
bool TVcompare(const TalentandVirtue &front,const TalentandVirtue &behind)
{
if(front.sum>behind.sum)
return true;
else if (front.sum==behind.sum&&front.Virtue_Grade>behind.Virtue_Grade)
return true;
else if (front.sum==behind.sum&&front.Virtue_Grade==behind.Virtue_Grade&&front.ID_Number<behind.ID_Number)
return true;
return false;
}
int main()
{
vector ssages;
vector<TalentandVirtue> nnoble;
vector<TalentandVirtue> ffool ;
vector<TalentandVirtue> oother;
TalentandVirtue TV;
int N,inc,L,H,add;
cin>>N>>L>>H;
for(inc=0,add=0;add<N;add++)
{
cin>>TV.ID_Number>>TV.Virtue_Grade>>TV.Talent_Grade;
TV.sum=TV.Virtue_Grade+TV.Talent_Grade;

if(TV.Virtue_Grade<L||TV.Talent_Grade
else{
if(TV.Virtue_Grade>=H&&TV.Talent_Grade>=H)
ssages.push_back(TV);
else if(TV.Virtue_Grade>=H)
nnoble.push_back(TV);
else if(TV.Virtue_Grade<H&&TV.Talent_Grade&&TV.Virtue_Grade>=TV.Talent_Grade)
ffool.push_back(TV);
else oother.push_back(TV);
inc++;}
}
cout<<
sort(ssages.begin(),ssages.end(),TVcompare);
sort(nnoble.begin(),nnoble.end(),TVcompare);
sort(ffool.begin(),ffool.end(),TVcompare);
sort(oother.begin(),oother.end(),TVcompare);
vector<TalentandVirtue>::iterator it;
for(it=ssages.begin();it!=ssages.end();it++)
printf("%08d %d %d\n",it->ID_Number,it->Virtue_Grade,it->Talent_Grade);
for(it=nnoble.begin();it!=nnoble.end();it++)
printf("%08d %d %d\n",it->ID_Number,it->Virtue_Grade,it->Talent_Grade);
for(it=ffool.begin();it!=ffool.end();it++)
printf("%08d %d %d\n",it->ID_Number,it->Virtue_Grade,it->Talent_Grade);
for(it=oother.begin();it!=oother.end();it++)
printf("%08d %d %d\n",it->ID_Number,it->Virtue_Grade,it->Talent_Grade);
return 0;
}



特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报
评论区(0)
按点赞数排序
用户头像
精选文章
thumb 中国研究员首次曝光美国国安局顶级后门—“方程式组织”
thumb 俄乌线上战争,网络攻击弥漫着数字硝烟
thumb 从网络安全角度了解俄罗斯入侵乌克兰的相关事件时间线
下一篇
Java中的集合浅析 2022-11-30 08:45:18