1055. The World's Richest (25)
2017-02-11 15:51
302 查看
这题要剪支,每个年龄段最多输出100人,所以每个年龄最多保留100人就可以了,不然第二点超时
不过我第一次用的方法第二点过了,第三点超时了。。。还多赚一分lol
不过我第一次用的方法第二点过了,第三点超时了。。。还多赚一分lol
#include<iostream> #include<algorithm> #include<vector> #include<map> #include<string> #include<set> #include<stack> using namespace std; struct rec{ string name; int age; int worth; }; int n, k; bool comp(rec a, rec b){ if(a.worth != b.worth) return a.worth > b.worth; else if(a.age != b.age) return a.age < b.age; else return a.name < b.name; } vector<rec> all_recs, keep_recs; int allages[201] = {0}; int main(){ cin>>n>>k; for(int i = 0; i < n; i++){ rec a; cin>>a.name; scanf("%d%d",&a.age,&a.worth); all_recs.push_back(a); } sort(all_recs.begin(),all_recs.end(),comp); for(int i = 0; i < n; i++){ int tempage = all_recs[i].age; if(allages[tempage] < 100){ allages[tempage]++; keep_recs.push_back(all_recs[i]); } } for(int i = 1; i <= k; i++){ int num, low, high; scanf("%d%d%d",&num,&low,&high); printf("Case #%d:\n",i); int count = 0; for(int j = 0; j < keep_recs.size() && count < num; j++){ if(keep_recs[j].age >= low && keep_recs[j].age <= high){ printf("%s %d %d\n",keep_recs[j].name.c_str(),keep_recs[j].age,keep_recs[j].worth); count++; } } if(count == 0){ printf("None\n"); } } return 0; }
相关文章推荐
- libdvbpsi源码分析(四)PAT表解析/重建
- PAT配置
- 什么是端口复用动态地址转换(PAT) 介绍配置实例
- MikroTik layer7-protocol
- PAT是如何工作的
- PAT 乙级题:1002. 写出这个数 (20)
- PAT (Advanced Level) Practise 1001-1010
- PAT (Basic Level) Practise (中文)
- 数据结构学习与实验指导(一)
- PAT Basic Level 1001-1010解题报告
- PAT 数素数
- PAT 福尔摩斯的约会
- PAT 德才论
- PAT 月饼
- 1001. 害死人不偿命的(3n+1)猜想
- 1002. 写出这个数
- 1032. 挖掘机技术哪家强
- 1001. 害死人不偿命的(3n+1)猜想 (PAT basic)
- 1002. 写出这个数(PAT Basic)
- 1004. 成绩排名(PAT Basic)