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 ...
随机推荐
- Quartz.net 定时任务之储存与持久化和集群(源码)
一.界面 1.这篇博客不上教程.直接看结果(包括把quartz任务转换成Windows服务) (1).主界面 (2).添加任务(默认执行) (3).编辑(默认开启) (4).关闭和开启 2.代码说明 ...
- Centos6下关于系统用户密码规则-运维笔记
随着linux使用的普遍,对于linux用户以及系统的安全要求越来越高,而用户密码复杂程度是系统安全性高低的首要体现.因此如何对linux下用户的密码进行规则限制,以保证用户必须使用复杂的密码,杜绝用 ...
- 【2016.3.19】作业 分析一个很有(wu)趣(liao)的小程序
问题1:这个程序要找的是符合什么条件的数? 能够整除2-32中所有数仅除了在此之中的两个相邻的数,比如能整除2-29,且不能整除30,31.当然,这只是举个例子. 问题2:这样的数存在么?符合这一条件 ...
- 12.10 Daily Scrum
各种大作业,进度会放缓一些. Today's Task Tomorrow's Task 丁辛 完善餐厅列表,显示距离. 实现和菜谱相关的餐厅列表. 邓亚梅 ...
- 软件工程启程篇章:结对编程和进阶四则运算(197 & 199)
0x01 :序言:无关的事 I wrote a sign called "Dead End" in front of myself, but love crossed it wit ...
- oracle alter
ALTER TABLE (表名) ADD CONSTRAINT (索引名);ALTER TABLE (表名) DROP CONSTRAINT (索引名); ALTER TABLE (表名) ADD ( ...
- 百度地图marker点击任意一个当前的变化,其余的marker不变
百度地图marker点击任意一个当前的变化,其余的marker不变 最近做的百度地图,遇到一个问题,就是在for循环里面执行marker的点击事件 没有可以比对的对象,每次点击marker的时候,i都 ...
- Jquery 组 标签页
<!DOCTYPE html><html lang="zh-cn"><head> <meta charset="utf-8&qu ...
- PHP 4种输出的方式
<?php //测试用的数组 $info = array('11'=>'aaa', '22'=>'bbb', '33'=>'ccc'); //第一种,将整个数组作为一个对象输出 ...
- ubuntu解压zip文件
step1 # 安装解压软件 sudo apt-get install unzip step # 2 解压文件 unzip xxxxx.zip