PAT_A1055#The World's Richest
Source:
Description:
Forbes magazine publishes every year its list of billionaires based on the annual ranking of the world's wealthiest people. Now you are supposed to simulate this job, but concentrate only on the people in a certain range of ages. That is, given the net worths of N people, you must find the M richest people in a given range of their ages.
Input Specification:
Each input file contains one test case. For each case, the first line contains 2 positive integers: N (≤) - the total number of people, and K (≤) - the number of queries. Then N lines follow, each contains the name (string of no more than 8 characters without space), age (integer in (0, 200]), and the net worth (integer in [−]) of a person. Finally there are K lines of queries, each contains three positive integers: M (≤) - the maximum number of outputs, and [
Amin,Amax] which are the range of ages. All the numbers in a line are separated by a space.
Output Specification:
For each query, first print in a line
Case #X:whereXis the query number starting from 1. Then output the M richest people with their ages in the range [Amin,Amax]. Each person's information occupies a line, in the formatName Age Net_Worth
The outputs must be in non-increasing order of the net worths. In case there are equal worths, it must be in non-decreasing order of the ages. If both worths and ages are the same, then the output must be in non-decreasing alphabetical order of the names. It is guaranteed that there is no two persons share all the same of the three pieces of information. In case no one is found, output
None.
Sample Input:
12 4
Zoe_Bill 35 2333
Bob_Volk 24 5888
Anny_Cin 95 999999
Williams 30 -22
Cindy 76 76000
Alice 18 88888
Joe_Mike 32 3222
Michael 5 300000
Rosemary 40 5888
Dobby 24 5888
Billy 24 5888
Nobody 5 0
4 15 45
4 30 35
4 5 95
1 45 50
Sample Output:
Case #1:
Alice 18 88888
Billy 24 5888
Bob_Volk 24 5888
Dobby 24 5888
Case #2:
Joe_Mike 32 3222
Zoe_Bill 35 2333
Williams 30 -22
Case #3:
Anny_Cin 95 999999
Michael 5 300000
Alice 18 88888
Cindy 76 76000
Case #4:
None
Keys:
- 模拟题
Attention:
- 用string的I/O会超时,换字符数组就好了
Code:
/*
Data: 2019-07-15 18:45:09
Problem: PAT_A1055#The World's Richest
AC: 21:45 题目大意:
排序
输入:
第一行给出,人数N<=1e5,查询数K<=1e3
接下来N行,name,age,worth
接下来K行,入选人数,最小年龄,最大年龄
输出:
按照worth递减,age递增,name递增
*/ #include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
struct node
{
char name[];
int age,worth;
}temp;
vector<node> info; bool cmp(const node &a, const node &b)
{
if(a.worth != b.worth)
return a.worth > b.worth;
else if(a.age != b.age)
return a.age < b.age;
else
return strcmp(a.name,b.name)<;
} int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif int n,m,l,r;
scanf("%d %d", &n,&m);
for(int i=; i<n; i++)
{
scanf("%s %d %d\n", temp.name,&temp.age,&temp.worth);
info.push_back(temp);
}
sort(info.begin(),info.end(),cmp);
for(int i=; i<=m; i++)
{
scanf("%d%d%d", &n,&l,&r);
printf("Case #%d:\n", i);
vector<node> ans;
for(int j=; j<info.size(); j++)
{
if(info[j].age>=l && info[j].age<=r)
ans.push_back(info[j]);
if(ans.size()==n) break;
}
if(ans.size() == ) printf("None\n");
for(int j=; j<ans.size(); j++)
printf("%s %d %d\n", ans[j].name,ans[j].age,ans[j].worth);
} return ;
}
PAT_A1055#The World's Richest的更多相关文章
- 1055. The World's Richest (25)
Forbes magazine publishes every year its list of billionaires based on the annual ranking of the wor ...
- PAT1055:The World's Richest
1055. The World's Richest (25) 时间限制 400 ms 内存限制 128000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...
- PAT A1055 The World's Richest (25 分)——排序
Forbes magazine publishes every year its list of billionaires based on the annual ranking of the wor ...
- A1055. The World's Richest
Forbes magazine publishes every year its list of billionaires based on the annual ranking of the wor ...
- PAT 1055 The World's Richest[排序][如何不超时]
1055 The World's Richest(25 分) Forbes magazine publishes every year its list of billionaires based o ...
- 7-31 The World's Richest(25 分)
Forbes magazine publishes every year its list of billionaires based on the annual ranking of the wor ...
- pat1055. The World's Richest (25)
1055. The World's Richest (25) 时间限制 400 ms 内存限制 128000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...
- A1055 The World's Richest(25 分)
A1055 The World's Richest(25 分) Forbes magazine publishes every year its list of billionaires based ...
- PATA1055 The World's Richest (25 分)
1055 The World's Richest (25 分) Forbes magazine publishes every year its list of billionaires based ...
随机推荐
- Leetcode 跳跃游戏 II
题目链接:https://leetcode-cn.com/problems/jump-game-ii/ 题目大意: 略. 分析: 贪心 + DP. 代码如下: class Solution { pub ...
- 力扣算法题—149Max Points on a line
Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. ...
- EF复合主键
[Key,Column(Order = )] [Key,Column(Order = )]
- yum update过程中失败后再次执行出现“xxxx is a duplicate with xxxx”问题
问题现象: 解决办法: 利用yum-uitls中的工具package-cleanup指令,使用方法见下图,具体可通过man package-cleanup查询 列出重复的rpm包 pac ...
- Laravel4 最佳学习代码以及资料推荐(转)
https://github.com/andrew13/Laravel-4-Bootstrap-Starter-Site 充分展现了Laravel的强大之处 Laravel虽然上手难度会比其他框架大很 ...
- flask中配置并使用mongodb
在你安装并运行了mongodb的情况下: 随便在一个文件中写入以下代码: import pymongo client = pymongo.MongoClient(host="localhos ...
- springboot整合netty,多种启动netty的方式,展现bean得多种启动方法
首先讲解下,spring中初始化加载问题: 很多时候,我们自己写的线程池,还有bean对象,还有其他的服务类,都可以通过,相关注解进行交给spring去管理,那么我们如何让nettyserver初始化 ...
- How to easily Detect Objects with Deep Learning on Raspberry Pi
https://medium.com/nanonets/how-to-easily-detect-objects-with-deep-learning-on-raspberrypi-225f29635 ...
- shell专用参数变量
- shell script test指令的测试功能 &和&&,|和|| 区别 变量名赋值=号前后的空格问题(天坑)
小程序告一段落,达到阶段性目标.下一步继续Linux的学习....脑子不够用啊...真费... 书中介绍..检测系统某些文件或者相关属性时,用test指令.. 例如.测试某个文档目录是否存在可以 t ...