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:
whereX
is 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 ...
随机推荐
- PAT_A1037#Magic Coupon
Source: PAT A1037 Magic Coupon (25 分) Description: The magic shop in Mars is offering some magic cou ...
- log4j日志格式化
Apache log4j 提供了各种布局对象,每一个对象都可以根据各种布局格式记录数据.另外,也可以创建一个布局对象格式化测井数据中的特定应用的方法. 所有的布局对象 - Appender对象收到 L ...
- javascript常用经典算法实例详解
javascript常用经典算法实例详解 这篇文章主要介绍了javascript常用算法,结合实例形式较为详细的分析总结了JavaScript中常见的各种排序算法以及堆.栈.链表等数据结构的相关实现与 ...
- Spring Boot控制上传文件大小
spring: http: multipart: max-file-size: 5MB max-request-size: 20MB
- fedora 25重新安装引导
引导区被其他系统给覆盖了,重新安装引导 grub2-install /dev/sdb GRUB_SAVEDEFAULT=true BIOS grub2-mkconfig -o /boot/grub2/ ...
- JS提示信息来检测相应id的标签
2015-07~2015-08 (其中$为document.getElementById()) 使用span提示信息来检测相应id的标签,没有返回值 infoTips("LRYH" ...
- ubuntu 设置root密码
- ionic3 多级联动城市选择插件 ion-multi-picker
1.效果演示 2.npm安装扩展包依赖 ion-multi-picker 组件 npm install ion-multi-picker --save 3.在app.module.ts中导入插件模块 ...
- KiCAD原理图导出PDF方法
KiCAD原理图导出为PDF 1.文件->绘制 2.按照下图选择保存目录和输出格式后,选择绘制当前页或者所有页
- No symbol table is loaded. Use the "file" command.
No symbol table is loaded. Use the "file" command. gdb 1. 首先使用gcc -g .c文件 -o 可执行文 ...