PAT甲级1055 The World's Richest【排序】
题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805421066272768
题意:
给定n个人的名字,年龄和身价。k次查询,每次询问某一个年龄区间的人的前m个最富有的人。
思路:
我好傻系列。
刚开始撒比排序先按照年龄从小到大排然后存某一年龄的开始下标和个数。然后每次复制出某一区间的人,再按答案要求排序。
好傻。后来想想直接就按照答案的要求排序,对于符合要求的那些人,他们输出的时候的相对顺序就是固定的。
所以我只需要从头到尾找到前m个符合要求的人就可以了。
#include<stdio.h>
#include<stdlib.h>
#include<map>
#include<set>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue> #define inf 0x7fffffff
using namespace std;
typedef long long LL;
typedef pair<int, int> pr; int n, k;
const int maxn = 1e5 + ;
struct node{
string name;
int age;
int net_worth;
}peo[maxn], tmp[maxn]; bool cmp1(node a, node b)
{
if(a.age == b.age)return a.net_worth > b.net_worth;
else return a.age < b.age;
} bool cmp(node a, node b)
{
if(a.net_worth == b.net_worth){
if(a.age == b.age)return a.name < b.name;
else return a.age < b.age;
}
else return a.net_worth > b.net_worth;
} int main()
{
scanf("%d%d", &n, &k);
for(int i = ; i <= n; i++){
cin>>peo[i].name>>peo[i].age>>peo[i].net_worth;
}
sort(peo + , peo + + n, cmp); int m, amin, amax;
for(int cas = ; cas <= k; cas++){
scanf("%d%d%d", &m, &amin, &amax);
printf("Case #%d:\n", cas); int cnt = ;
for(int pos = ; pos <= n; pos++){
if(peo[pos].age >= amin && peo[pos].age <= amax){
cnt++;
cout<<peo[pos].name;
printf(" %d %d\n", peo[pos].age, peo[pos].net_worth);
}
if(cnt == m)break;
}
if(cnt == ){
printf("None\n");
}
}
return ;
}
PAT甲级1055 The World's Richest【排序】的更多相关文章
- 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 1055 The World's Richest[排序][如何不超时]
1055 The World's Richest(25 分) Forbes magazine publishes every year its list of billionaires based o ...
- PAT甲级——A1055 The World's Richest
Forbes magazine publishes every year its list of billionaires based on the annual ranking of the wor ...
- PAT甲级题分类汇编——排序
本文为PAT甲级分类汇编系列文章. 排序题,就是以排序算法为主的题.纯排序,用 std::sort 就能解决的那种,20分都算不上,只能放在乙级,甲级的排序题要么是排序的规则复杂,要么是排完序还要做点 ...
- PAT甲级1017题解——模拟排序
题目分析: 本题我第一次尝试去做的时候用的是优先队列,但是效率不仅代码量很大,而且还有测试样例过不去,很显然没有找到一个好的数据结构来解决这道题目(随着逐渐的刷PAT甲级的题会发现有时选择一个好的解题 ...
- PAT甲级题解(慢慢刷中)
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6102219.html特别不喜欢那些随便转载别人的原创文章又不给 ...
- 【转载】【PAT】PAT甲级题型分类整理
最短路径 Emergency (25)-PAT甲级真题(Dijkstra算法) Public Bike Management (30)-PAT甲级真题(Dijkstra + DFS) Travel P ...
- PAT甲级题分类汇编——序言
今天开个坑,分类整理PAT甲级题目(https://pintia.cn/problem-sets/994805342720868352/problems/type/7)中1051~1100部分.语言是 ...
- PAT 甲级真题题解(1-62)
准备每天刷两题PAT真题.(一句话题解) 1001 A+B Format 模拟输出,注意格式 #include <cstdio> #include <cstring> #in ...
随机推荐
- [Aaronyang] 写给自己的WPF4.5 笔记9[复杂数据处理三步曲,数据展示ListView泪奔2/3]
我的文章一定要做到对读者负责,否则就是失败的文章 --------- www.ayjs.net aaronyang技术分享 作者留言: 小小的推荐,作者的肯定,读者的支持. ...
- mysql 编译安装 window篇
传送门 # mysql下载地址 https://www.mysql.com/downloads/ # 找到MySQL Community Edition (GPL) https://dev.mysql ...
- java8学习的一点总结
最近研究了一下java8 弄了几个例子学习了一下用法: 创建了一个实体类: @Data public class Apple { private Integer id; private String ...
- [APM] 2个实例+5个维度解读APM技术
为了加深EGO会员之间的相互了解,同时也为大家提供更多线上相互学习交流的机会,EGO正式启动会员群线上分享活动.本文是根据陈靖华分享主题“APM的价值”的内容整理而成. 第二期分享嘉宾:陈靖华,EGO ...
- 十大高明的Google搜索技巧
WHY 对于google检索,有时需要技巧会得到更好的检索结果,不用简单输入关键字检索后,一个个去浏览.对于这些技巧,基本都知道,但是如果不经常用,总是忘了,又得重新搜索下具体使用方法,这里就把它放到 ...
- Python3多线程之间的执行顺序问题
[本文出自天外归云的博客园] 一个多线程的题:定义三个线程ID分别为ABC,每个线程打印10遍自己的线程ID,按ABCABC……的顺序进行打印输出. 我的解法: from threading impo ...
- 【Spring源码分析】Bean加载流程概览(转)
转载自:https://www.cnblogs.com/xrq730/p/6285358.html 代码入口 之前写文章都会啰啰嗦嗦一大堆再开始,进入[Spring源码分析]这个板块就直接切入正题了. ...
- maven 如何引入本地jar包
比如我下载了 一.怎么添加jar到本地仓库呢?步骤:1.cmd命令进入该jar包所在路径2.执行命令:mvn install:install-file -Dfile=lucene-queryparse ...
- Top useful .Net extension methods
Special extension methods were released in C# 3.0. Developers have continuously been looking for way ...
- 用OpenGL实现动态的立体时钟
(在学期末做的图形学课程设计,特将学习心得整理如下) 一.设计思路 1,设计一个平面的时钟: 按照 钟面——>中心点——>刻度——>时针——>分针——>秒针 的顺序绘制. ...