题意:

输入两个正整数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. 题解 P1453 【城市环路】

    P1453 城市环路 感觉基环树(or环套树)的题目一般都是找到树上的环,断掉一条边再进行树上的操作(如noip2018P5022 旅行) 双倍经验:P2607 [ZJOI2008]骑士 P1453和 ...

  2. 剑指offer 面试题36.二叉搜索树与双向链表

    中序递归,一个pre节点记录前一个节点 /* struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; Tre ...

  3. (原)Vue 单文件组件安装 (创建vue-cli 项目)

    更新于20200220 题外话:久违了我的博客园 正题: 1.准备工作,安装环境 1.安装node 官网下载安装即可  -- 配置环境变量 2.安装npm (基于node.js 包管理器) 3.安装c ...

  4. C语言程序设计100例之(27):回旋方阵

    例27        回旋方阵 问题描述 编写程序,生成从内到外是连续的自然数排列的回旋方阵.例如,当n=3和n=4时的回旋方阵如下图1所示. 图1  由内到外回旋方阵 输入格式 一个正整数n(1≤n ...

  5. 网站调用qq第三方登录

    1. 准备工作 (1) 接入QQ登录前,网站需首先进行申请,获得对应的appid与appkey,以保证后续流程中可正确对网站与用户进行验证与授权. ① 注册QQ互联开发者账号  网址  https:/ ...

  6. 【网易官方】极客战记(codecombat)攻略-地牢-辐射光环

    关卡连接: https://codecombat.163.com/play/level/radiant-aura 骷髅,恐惧还是回避? 简介: 敬请期待! 默认代码 # 捡起发光石,让骷髅怪远离你一会 ...

  7. 第十一篇 深入Python的dict和set(二)

  8. rest framework 序列化之depth遇到用户表外键的尴尬情况

    rest framework 序列化之depth遇到用户表外键的尴尬情况 问题:ModelSerializer序列化使用depth=1直接扩表把用户表所有信息查询出来的情况 class xxxSeri ...

  9. springboot笔记-2-.核心的上下文以及配置扫描解析(上)

    前言 上一节中说明了springboot是如何做到自动发现配置的,那么本节看下spring如何创建上下文并解析这些配置,加载我们注册到容器管理中的类.上节已经成功的创建了SpringApplicati ...

  10. HttpServer带阻塞性能比较

    服务端在返回hello,world! 之前先阻塞一秒钟,模拟访问DB等耗时操作. Netty 我直接在 WorkerGroup 里头sleep,用同步阻塞线程模型的方式来编程,所以性能暴降. Joob ...