【PAT甲级】1055 The World's Richest (25 分)
题意:
输入两个正整数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 分)的更多相关文章
- 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 ...
- PAT甲级:1036 Boys vs Girls (25分)
PAT甲级:1036 Boys vs Girls (25分) 题干 This time you are asked to tell the difference between the lowest ...
- PAT甲级:1089 Insert or Merge (25分)
PAT甲级:1089 Insert or Merge (25分) 题干 According to Wikipedia: Insertion sort iterates, consuming one i ...
- PAT 甲级 1145 Hashing - Average Search Time (25 分)(读不懂题,也没听说过平方探测法解决哈希冲突。。。感觉题目也有点问题)
1145 Hashing - Average Search Time (25 分) The task of this problem is simple: insert a sequence of ...
- 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 ...
- 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 ...
- PAT 甲级 1039 Course List for Student (25 分)(字符串哈希,优先队列,没想到是哈希)*
1039 Course List for Student (25 分) Zhejiang University has 40000 students and provides 2500 cours ...
- 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 ...
- PAT甲级1055 The World's Richest【排序】
题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805421066272768 题意: 给定n个人的名字,年龄和身价. ...
随机推荐
- win10 解决.net framework 3.5 安装报错 0x80240438
打开注册表:cmd+r 输入regedit,确定:找到路径HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU ...
- SSI注入漏洞
简介 SSI是英文Server Side Includes的缩写,翻译成中文就是服务器端包含的意思.从技术角度上说,SSI就是在HTML文件中,可以通过注释行调用的命令或指针.SSI具有强大的功能,只 ...
- Python六剑客
1.切片 切片:截取可迭代对象的部分内容(list,tuple,dict,set,str) 2.列表解析式 列表解析式可以快速的生成一个列表 不带if条件的: 格式:[expression for i ...
- .NTE Core Web API Example
Source from :https://www.codeproject.com/Articles/1260600/Speed-up-ASP-NET-Core-WEB-API-application- ...
- Collection两个常见的集合类型: ArrayList可重复集有序 ,HashSet不可重复集
package seday11; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; ...
- my97日期控件弹出位置显示异常
使用my97日期选择控件的时候,如果整个页面是有滚动条的,根据触发显示日期的控件的父控件的position不同会显示不同的情况 1.position不为fixed则滑动滚动条,显示的日期层不会出现异常 ...
- Scanner的hasNext()方法
转自:https://blog.csdn.net/gao_zhennan/article/details/80562548 找到一篇关于hasNext()的常见问题的文章,记录一下
- Sass&Scss入门 选择器 混合器 导入 条件判断 迭代
Sass 基于ruby的一种将脚本解析成CSS的脚本语言.也可以说是一种预处理语言. Sass在css的语法基础上增加了变量.嵌套.混合.继承.导入等高级功能. 使用Sass与Sass样式库(如com ...
- 003 CSS汇总
字体属性:(font) 大小 {font-size: x-large;}(特大) xx-small;(极小) 一般中文用不到,只要用数值就可以,单位:PX.PD 样式 {font-style: obl ...
- 第一篇:thinkPHP学习目的
公司找人开发了一套程序,用的是thinkphp,我一直都是做前端的,后端对PHP也有一些了解,能看懂代码,但是不能写,因为公司不想再招人,嘱托我来维护. 翻看了thinkphp的官方文档,也去看了一下 ...