A1055. The World's Richest
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 (<=105) - the total number of people, and K (<=103) - 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 [-106, 106]) of a person. Finally there are K lines of queries, each contains three positive integers: M (<= 100) - 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:" where X 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 format
Name 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
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
typedef struct{
char name[];
int age;
int worth;
}info;
bool cmp(info a, info 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) < ;
} info people[];
int main(){
int N, K;
scanf("%d%d", &N, &K);
for(int i = ; i < N; i++){
scanf("%s %d %d", people[i].name, &people[i].age, &people[i].worth);
}
sort(people, people + N, cmp);
for(int i = ; i < K; i++){
int M, min_, max_, cnt = ;
scanf("%d%d%d", &M, &min_, &max_);
printf("Case #%d:\n", i + );
for(int j = ; j < N; j++){
if(people[j].age <= max_ && people[j].age >= min_){
printf("%s %d %d\n", people[j].name, people[j].age, people[j].worth);
cnt++;
}
if(cnt == M){
break;
}
}
if(cnt == )
printf("None\n");
}
cin >> K;
return ;
}
A1055. The World's Richest的更多相关文章
- A1055 The World's Richest(25 分)
A1055 The World's Richest(25 分) Forbes magazine publishes every year its list of billionaires based ...
- PAT A1055 The World's Richest (25 分)——排序
Forbes magazine publishes every year its list of billionaires based on the annual ranking of the wor ...
- PAT甲级——A1055 The World's Richest
Forbes magazine publishes every year its list of billionaires based on the annual ranking of the wor ...
- PAT_A1055#The World's Richest
Source: PAT A1055 The World's Richest (25 分) Description: Forbes magazine publishes every year its l ...
- 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 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 ...
随机推荐
- JQuery_自带的动画效果
1.方法: show:显示选中元素. hide:隐藏选中元素. toggle:显示或隐藏选中元素. fadeIn:将选中元素的不透明度逐步提升到100%. fadeOut:将选中元素的不透明度逐步降为 ...
- centos7下安装php+memcached简单记录
1)centos7下安装php 需要再添加一个yum源来安装php-fpm,可以使用webtatic(这个yum源对国内网络来说恐怕有些慢,当然你也可以选择其它的yum源) [root@nextclo ...
- 个人项目Individual Project:迷宫求解
源码的github链接: https://github.com/zhangxue520/test 1.1问题描述: a.问题描述:以一个m * n的长方阵表示迷宫,0和1分别表示迷 ...
- Sprint 冲刺第三阶段第3-5天 数据库代码
数据库代码: package com.example.brdemo; import android.app.Activity; import android.content.Intent; impor ...
- Sprint 冲刺第三阶段第3-5天
陈汝婷:数据库的实现 具体实现用户登录在数据库中查找,用户注册的时候可以将用户的具体信息存放于SD卡中.刚学Android的数据库的数据库,还有一些问题.所以这个问题一直拖了几天才解决.问老师问同学, ...
- What’s for Beta
经过和Travis与Zhongqiu讨论,我们希望我们发布的Beta版本会支持如下内容: Naïve long-term plan UI (Useable) Naïve long-term plan ...
- Windows 7 64位安装cURL
安装cURL. 1, 下载64位的SSL版cURL,网址: http://curl.download.nextag.com/download/curl-7.21.7-win64-ssl-sspi.zi ...
- 4-Python3从入门到实战—基础之数据类型(字符串-String)
Python从入门到实战系列--目录 字符串表示 在 Python 3版本中,字符串是以 Unicode 编码的:Python 中使用 ' '或者" "表示字符串 msg = 'H ...
- corosync+pacemaker的crmsh的常用指令介绍
配置crmsh的yum仓库,此仓库的RPM包有openSUSE提供,将这个network:ha-clustering:Stable.repo文件直接下载到本地并且命名为crmsh.repo wget ...
- opencv学习笔记(一)
摘要:最近要做一个和图像处理有联系的项目,从此走上了学习opencv的道路. 灰度图:2维矩阵 彩色图:3维矩阵 ps:目前大部分设备都是用无符号 8 位整数(类型为 CV_8U)表示像素亮度 Mat ...