题意:

输入两个正整数N和K(N<=1e5,K<=1000),接着输入N行,每行包括一位老板的名字,年龄和财富。K次询问,每次输入三个正整数M,L,R(M<=100,L,R<=200),输出至多M位年龄区间在L,R之间的老板的名字年龄和财富,按照财富降序,年龄升序,姓名字典序输出。

AAAAAccepted code:

 #define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
string s;
typedef struct account{
string name;
int age,worth;
};
bool cmp(account a,account b){
if(a.worth!=b.worth)
return a.worth>b.worth;
if(a.age!=b.age)
return a.age<b.age;
return a.name<b.name;
}
vector<account>vv;
vector<account>v;
int sum[];
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,k;
cin>>n>>k;
int age,w;
for(int i=;i<=n;++i){
cin>>s>>age>>w;
account tamp;
tamp.name=s;
tamp.age=age;
tamp.worth=w;
vv.push_back(tamp);
}
int x,l,r;
sort(vv.begin(),vv.end(),cmp);
for(int i=;i<vv.size();++i)//根据数据规模优化,大幅缩短运行时间
if(sum[vv[i].age]<){
v.push_back(vv[i]);
++sum[vv[i].age];
}
for(int i=;i<=k;++i){
cin>>x>>l>>r;
cout<<"Case #"<<i<<":\n";
int flag=;
for(int j=;j<v.size();++j){
if(v[j].age>=l&&v[j].age<=r){
cout<<v[j].name<<" "<<v[j].age<<" "<<v[j].worth<<"\n";
--x;
flag=;
}
if(!x)
break;
}
if(!flag)
cout<<"None\n";
}
return ;
}

【PAT甲级】1055 The World's Richest (25 分)的更多相关文章

  1. PAT 甲级 1055 The World's Richest (25 分)(简单题,要用printf和scanf,否则超时,string 的输入输出要注意)

    1055 The World's Richest (25 分)   Forbes magazine publishes every year its list of billionaires base ...

  2. PAT甲级:1036 Boys vs Girls (25分)

    PAT甲级:1036 Boys vs Girls (25分) 题干 This time you are asked to tell the difference between the lowest ...

  3. PAT甲级:1089 Insert or Merge (25分)

    PAT甲级:1089 Insert or Merge (25分) 题干 According to Wikipedia: Insertion sort iterates, consuming one i ...

  4. PAT 甲级 1145 Hashing - Average Search Time (25 分)(读不懂题,也没听说过平方探测法解决哈希冲突。。。感觉题目也有点问题)

    1145 Hashing - Average Search Time (25 分)   The task of this problem is simple: insert a sequence of ...

  5. PAT 甲级 1066 Root of AVL Tree (25 分)(快速掌握平衡二叉树的旋转,内含代码和注解)***

    1066 Root of AVL Tree (25 分)   An AVL tree is a self-balancing binary search tree. In an AVL tree, t ...

  6. PAT 甲级 1047 Student List for Course (25 分)(cout超时,string scanf printf注意点,字符串哈希反哈希)

    1047 Student List for Course (25 分)   Zhejiang University has 40,000 students and provides 2,500 cou ...

  7. PAT 甲级 1039 Course List for Student (25 分)(字符串哈希,优先队列,没想到是哈希)*

    1039 Course List for Student (25 分)   Zhejiang University has 40000 students and provides 2500 cours ...

  8. PAT (Advanced Level) Practice 1055 The World's Richest (25 分) (结构体排序)

    Forbes magazine publishes every year its list of billionaires based on the annual ranking of the wor ...

  9. PAT甲级1055 The World's Richest【排序】

    题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805421066272768 题意: 给定n个人的名字,年龄和身价. ...

随机推荐

  1. gnuplot 让您的数据可视化

    https://www.ibm.com/developerworks/cn/linux/l-gnuplot/index.html http://blog.sciencenet.cn/blog-3733 ...

  2. CentOS 7 使用笔记

    一.下载.解压或安装等命令: 目前自己用过的三个下载及安装命令:curl.wget.yum. yum用法: $ sudo yum install libpng16-1.6.29-alt1.i586.r ...

  3. c#显示行号设置方法

    工具→选项→文本编辑器→c#→常规→显示→勾选行号 反之取消即可.

  4. eclipse 添加主題

    在使用Eclipse过程中可能想更换下界面主题,此处介绍的是一款主题插件 Eclipse Color Theme 打开Eclipse,Help --> Eclipse Marketplace 在 ...

  5. 1.BMap(百度地图)第二次加载显示不全

    问题: bmap第一次加载显示没问题: 第二次 再次加载这个页面时,地图的显示出现了问题: . 分析问题出现原因:你要确保dom创建后且处于显示状态(即display不能为none)才能再次初始化地图 ...

  6. JS json对象(Object)和字符串(String)互转方法

    [JS json对象(Object)和字符串(String)互转方法] 参考:https://blog.csdn.net/wenqianla2550/article/details/78232706 ...

  7. php截取富文本框中的固定长度的字符

    ai,哎怎么赶脚自己写东西越来越小儿科了呢,现在连这个问题都找了好半天 因为后台是的内容是富文本编辑器编辑的,前台我傻逼的直接截取了字符串,然后样式啥的都乱了,找了半天是因为富文本的问题 其实解决办法 ...

  8. Qt QQuickView设置成无边框无标题栏

    #include <QGuiApplication> #include <QQmlApplicationEngine> #include <QQuickView> ...

  9. 其他 - win10 paged pool 内存溢出

    1. 概述 win 10 内存时不时溢出 目前还没有跟踪完毕 有空继续跟踪 2. 问题 win10 内存动不动就 往上涨 只涨不降 看各个进程又是正常的 3. 思路 先看看内存情况 妈的我 jvm 的 ...

  10. Linux环境下mysql报错:bash: mysql: command not found 的解决方法

    # mysql -u root-bash: mysql: command not found 原因:这是由于系统默认会查找/usr/bin下的命令. 如果这个命令不在这个目录下,当然会找不到命令. 我 ...