题目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【排序】的更多相关文章

  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 1055 The World's Richest[排序][如何不超时]

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

  3. PAT甲级——A1055 The World's Richest

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

  4. PAT甲级题分类汇编——排序

    本文为PAT甲级分类汇编系列文章. 排序题,就是以排序算法为主的题.纯排序,用 std::sort 就能解决的那种,20分都算不上,只能放在乙级,甲级的排序题要么是排序的规则复杂,要么是排完序还要做点 ...

  5. PAT甲级1017题解——模拟排序

    题目分析: 本题我第一次尝试去做的时候用的是优先队列,但是效率不仅代码量很大,而且还有测试样例过不去,很显然没有找到一个好的数据结构来解决这道题目(随着逐渐的刷PAT甲级的题会发现有时选择一个好的解题 ...

  6. PAT甲级题解(慢慢刷中)

    博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6102219.html特别不喜欢那些随便转载别人的原创文章又不给 ...

  7. 【转载】【PAT】PAT甲级题型分类整理

    最短路径 Emergency (25)-PAT甲级真题(Dijkstra算法) Public Bike Management (30)-PAT甲级真题(Dijkstra + DFS) Travel P ...

  8. PAT甲级题分类汇编——序言

    今天开个坑,分类整理PAT甲级题目(https://pintia.cn/problem-sets/994805342720868352/problems/type/7)中1051~1100部分.语言是 ...

  9. PAT 甲级真题题解(1-62)

    准备每天刷两题PAT真题.(一句话题解) 1001 A+B Format  模拟输出,注意格式 #include <cstdio> #include <cstring> #in ...

随机推荐

  1. tensorflow 中 reduce_sum 理解

    定义如下: reduce_sum( input_tensor, axis=None, keep_dims=False, name=None, reduction_indices=None ) redu ...

  2. 阿里云日志服务采集自建Kubernetes日志(标准输出日志)

    日志服务支持通过Logtail采集Kubernetes集群日志,并支持CRD(CustomResourceDefinition)进行采集配置管理.本文主要介绍如何安装并使用Logtail采集Kuber ...

  3. vmlinux,zImage,bzImage,vmlinuz,uImage,关系

    zImage和uImage的区别 一.vmlinuz vmlinuz是可引导的.压缩的内核.“vm”代表“Virtual Memory”.Linux 支持虚拟内存,不像老的操作系统比如DOS有640K ...

  4. Swift 计算三角形角度、两条边夹角

    /// 计算三点之间的角度 /// /// - Parameters: /// - p1: 点1 /// - p2: 点2(也是角度所在点) /// - p3: 点3 /// - Returns: 角 ...

  5. Hadoop2.2.0分布式安装配置详解[3/3]

    测试启动 按照下面的每一步执行,执行完一定要看输出的信息,注意warn或error或fatal的情况.因为这都是可能是问题出现的地方.出现一个问题,不解决,可能就会影响接下来的测试.这才是真正的工作量 ...

  6. System Monitor for Mac(系统监控工具)破解版安装

    1.软件简介    System Monitor 是 macOS 系统上的一款非常实用的 Mac 系统工具,System Monitor for mac 是一款六合一应用,您可以同时获得 CPU.RA ...

  7. goland激活码

    http://idea.youbbs.org      

  8. SNF快速开发平台MVC-甘特图

    上个月做了CS框架的甘特图样例,本月框架组人员又实现了BS的甘特图效果,而且效果也很不错哦 图形框可以直接拖拽调整时长时间: 新增节点:

  9. [DIOCP视频]-DIOCPFileServer视频

    本次视频简单讲解了DiocpFileServer + 客户端使用接口方式,通信方面可以方便的在DiocpBlockTcpClient和IdTcpClient组件之间切换. + 添加单独的EXE客户端( ...

  10. Spring Session Redis

    http://www.infoq.com/cn/articles/Next-Generation-Session-Management-with-Spring-Session