pat1055. The World's Richest (25)
1055. The World's Richest (25)
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)的更多相关文章
- PAT1055:The World's Richest
1055. The World's Richest (25) 时间限制 400 ms 内存限制 128000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue ...
- PATA1055 The World's Richest (25 分)
1055 The World's Richest (25 分) Forbes magazine publishes every year its list of billionaires based ...
- 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 ...
- 1055. The World's Richest (25)
Forbes magazine publishes every year its list of billionaires based on the annual ranking of the wor ...
- 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 ...
- 1055 The World's Richest (25分)(水排序)
Forbes magazine publishes every year its list of billionaires based on the annual ranking of the wor ...
- PAT (Advanced Level) 1055. The World's Richest (25)
排序.随便加点优化就能过. #include<iostream> #include<cstring> #include<cmath> #include<alg ...
- PAT甲题题解-1055. The World's Richest (25)-终于遇见一个排序的不水题
题目简单,但解题的思路需要转换一下,按常规思路肯定超时,推荐~ 题意:给出n个人的姓名.年龄和拥有的钱,然后进行k次查询,输出年龄在[amin,amx]内的前m个最富有的人的信息.如果财富值相同就就先 ...
- 【PAT甲级】1055 The World's Richest (25 分)
题意: 输入两个正整数N和K(N<=1e5,K<=1000),接着输入N行,每行包括一位老板的名字,年龄和财富.K次询问,每次输入三个正整数M,L,R(M<=100,L,R<= ...
随机推荐
- js数组与 json 的区别
一,数组 1. 定义一维数组:var s1=new Array(); s1=[1,2,3,4]或者s1[0]=1,s1[1]=2,s1[3]=3,s1[4]=4; alert(s1[0]); 结果为1 ...
- 问题:HttpWebRequest request post 传参; 结果:好用的C# HttpWebRequest用Post同时提交参数和文件的封装类
在项目中,本来都是在站内进行数据交互的,后来又加进来一个买的php网站(艹).需要进行数据交互,在没有考虑使用web服务的情况下,只有通过Post提交到页面进行数据交互是最好的方式了. 我这边使用的是 ...
- shell入门-sort排序
命令:sort 选项:-t:-kn 指定根据某段来排序 这里n代表数字,范围指定n,N.从n到N范围 -n 按数字顺序排列 -r 反序排列 -u 去重复排序 -un 数字顺序排列并去重复,系 ...
- /*透明度设置的两种方式,以及hover的用法,fixed,(relative,absolute)这两个一起用*/
<!DOCTYPE html> /*透明度设置的两种方式,以及hover的用法,fixed,(relative,absolute)这两个一起用*/ <html lang=" ...
- 一个自动修改本地IP地址的BAT
set /a num1=%random%%%200+1+1 //生成随机数set ip=192.168.1.//ip 主体set ip1=%ip%%num1% //拼接两部分cmd /c netsh ...
- JConsole远程监控配置
首先,看本机(Windows)安装了JRE没 Win > CMD 打开命令窗口 如有安装,则会显示以下版本信息:若没有显示,就安装吧 C:\Users\Administrator>java ...
- 积累遇到过的linux终端操作指令
mkdir mkdir命令是常用的命令,用来建立空目录,它还有2个常用参数: -m, --mode=模式 设定权限<模式> (类似 chmod) -p, --parents 需要时创建上层 ...
- 关于 char 和 unsigned char 的区别
首先卖个关子: 为什么网络编程中的字符定义一般都为无符号的字符? char buf[16] = {0}; unsigned char ubuf[16] = { 0 }; 上面两个定义的区别是: ...
- 【转】Subversion快速入门教程-动画演示
如何快速建立Subversion服务器,并且在项目中使用起来,这是大家最关心的问题,与CVS相比,Subversion有更多的选择,也更加的容易,几个命令就可以建立一套服务器环境,可以使用起来,这里配 ...
- hdu1072
#include <iostream> #include <cstdio> #include <cstring> #include <queue> us ...