【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个人的名字,年龄和身价. ...
随机推荐
- TCL create list from file
proc create_list {filename {prompt verbose} {opts "" }} { set list_return {} if {[file exi ...
- layer.open 回调函数
官方资料:http://www.layui.com/doc/modules/layer.html 在一个弹出框中新增个按钮,点击按钮后执行自己的语句(返回上一页并刷新). layer.open({ti ...
- 三分钟快速上手TensorFlow 2.0 (上)——前置基础、模型建立与可视化
本文学习笔记参照来源:https://tf.wiki/zh/basic/basic.html 学习笔记类似提纲,具体细节参照上文链接 一些前置的基础 随机数 tf.random uniform(sha ...
- [python]Python 字典(Dictionary) update()方法
update() 函数把字典dict2的键/值对更新到dict里.如果后面的键有重复的会覆盖前面的语法dict.update(dict2) dict = {'Name': 'Zara', 'Age': ...
- Django - DRF自带的token认证和JWT区别
问题重现 当查看DRF 文档时发现DRF内置的token是存储在数据库里,这和我在网上搜索资料时认识的token-based authentication有出入. from rest_framewor ...
- Sql 中获取年月日时分秒的函数
getdate():获取系统当前时间 dateadd(datepart,number,date):计算在一个时间的基础上增加一个时间后的新时间值,比如:dateadd(yy,30,getdate()) ...
- the MTS failed last time时的解决办法
关于6.6.3SP2版本提示The MTS failed last time 1.1 发生前提条件 在重启系统 shutdown -r now后,网页打不开,发现MTS服务无法启动,我自己涉及的 ...
- python函数编程闯关总结
文件处理相关 1,编码问题 (1)请问python2与python3中的默认编码是什么? python .x默认的字符编码是ASCII,默认的文件编码也是ASCII python .x默认的字符编码是 ...
- python-线程池的两种实现方式 【转载】
#!/usr/bin/env python # -*- coding:utf-8 -*- import queue import threading import contextlib import ...
- Sunday算法浅谈
一.Sunday算法简介 Sunday算法在我看来比起Kmp和bm都更加容易理解,代码实现也更加简洁.Sunday算法由Daniel M.Sunday在1990年提出,它的思想跟BM算法很相似只不过S ...