1055. The World's Richest (25)

时间限制
400 ms
内存限制
128000 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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<algorithm>
#include<iostream>
#include<cstring>
#include<queue>
#include<vector>
#include<cmath>
#include<string>
#include<map>
#include<set>
#include<stack>
using namespace std;
struct person{
char name[];
int age,worth;
};
bool cmp(person a,person b){
if(a.worth==b.worth){
if(a.age==b.age){
return strcmp(a.name,b.name)<;
}
return a.age<b.age;
}
return a.worth>b.worth;
}
int main()
{
//freopen("D:\\INPUT.txt","r",stdin);
int m,k,i,j;
scanf("%d %d",&m,&k);
person *per=new person[m+];
for(i=;i<m;i++){
scanf("%s %d %d",per[i].name,&per[i].age,&per[i].worth);
}
sort(per,per+m,cmp);
int amount,minage,maxage;
for(i=;i<=k;i++){
scanf("%d %d %d",&amount,&minage,&maxage);
printf("Case #%d:\n",i);
bool can=false;
for(j=;j<m;j++){
if(!amount){
break;
}
if(per[j].age>=minage&&per[j].age<=maxage){
amount--;
can=true;
printf("%s %d %d\n",per[j].name,per[j].age,per[j].worth);
}
}
if(!can){
printf("None\n");
}
}
delete []per;
return ;
}

pat1055. The World's Richest (25)的更多相关文章

  1. PAT1055:The World's Richest

    1055. The World's Richest (25) 时间限制 400 ms 内存限制 128000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...

  2. PATA1055 The World's Richest (25 分)

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

  3. 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 ...

  4. 1055. The World's Richest (25)

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

  5. PAT (Advanced Level) Practice 1055 The World's Richest (25 分) (结构体排序)

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

  6. 1055 The World's Richest (25分)(水排序)

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

  7. PAT (Advanced Level) 1055. The World's Richest (25)

    排序.随便加点优化就能过. #include<iostream> #include<cstring> #include<cmath> #include<alg ...

  8. PAT甲题题解-1055. The World's Richest (25)-终于遇见一个排序的不水题

    题目简单,但解题的思路需要转换一下,按常规思路肯定超时,推荐~ 题意:给出n个人的姓名.年龄和拥有的钱,然后进行k次查询,输出年龄在[amin,amx]内的前m个最富有的人的信息.如果财富值相同就就先 ...

  9. 【PAT甲级】1055 The World's Richest (25 分)

    题意: 输入两个正整数N和K(N<=1e5,K<=1000),接着输入N行,每行包括一位老板的名字,年龄和财富.K次询问,每次输入三个正整数M,L,R(M<=100,L,R<= ...

随机推荐

  1. 从生成文件对比两种创建虚拟机的方式:boot from image和boot from bootable-volume

    1. 创建bootable-volume(参考:http://docs.openstack.org/grizzly/openstack-compute/admin/content/instance-c ...

  2. delphi 线程教学第三节:设计一个有生命力的工作线程

    第三节:设计一个有生命力的工作线程   创建一个线程,用完即扔.相信很多初学者都曾这样使用过. 频繁创建释放线程,会浪费大量资源的,不科学.   1.如何让多线程能多次被复用?   关键是不让代码退出 ...

  3. 关闭socket以及Socket选项

    1 关闭socket ·1)socket套接字使用完毕之后,我们需要将起及时的关闭,正如输入输出流的关闭是一样的:在我上一篇文章中介绍了如何模拟httpClient发送请求数据:这里我还是使用上一篇文 ...

  4. [多路dp]更难的矩阵取数问题

    https://www.51nod.com/tutorial/course.html#!courseId=11&isCurrent=1 解题关键:1.注意i和j的最大取值都是n,k是i与j的和 ...

  5. 使用log4j出现缺失com.sun.jdmk:jmxtools:jar:1.2.1

    用maven引用log4j出现缺失com.sun.jdmk:jmxtools:jar:1.2.1的错误提示 解决方案一:使用1 .2 .15之前版本的log4j 解决方二: <dependenc ...

  6. C++11新标准

    1. 新类型 long long和unsigned long long: char16_t 和 char32_t: 新增原始字符串: 2. 统一的初始化 C++11扩大了用大括号括起的列表(初始化列表 ...

  7. 基于TMF SID的高可扩展性数据模型

    基于TMF SID的高可扩展性数据模型 前言 此文根据TMF SID规范撰写,欢迎大家提出建议和意见. TMF文档版权信息 Copyright © TeleManagement Forum 2013. ...

  8. Fiddler开启Https的时候出现unable to configure windows to trust Fiddler Root certificate问题

    前言 通过log页面看到错误为:访问控制列表(ACL)结构无效. 网上(baidu,bing,google)各种方式都试过了: 如重置证书(Reset all certificates) 导出证书到本 ...

  9. 使用配置类而不使用XML文件(代替bean.xml)对spring进行配置

    以下类是一个配置类,它的作用和bean.xml是一样的注解: @Configuration 作用: 用于指定当前类是一个spring配置类,当创建容器时会从该类上加载注解. 获取容器时需要使用Anno ...

  10. 2018上海大都会邀请赛J(数位DP)

    #include<bits/stdc++.h>using namespace std;int num[20];//按位储存数字int mod;long long dp[20][110][1 ...