1055 The World's Richest(25 分)

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。

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 (≤10
​​ ) - the total number of people, and K (≤10
​​ ) - 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 [−10
​​ ,10
​​ ]) 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:


using namespace std;
const int maxn=1e5+10;
struct Node{
    int age,worth;
    char name[10];

bool cmp(Node a,Node b){
    if(a.worth !=b.worth )
        return a.worth >b.worth ;
    else if(a.age !=b.age )
        return a.age <b.age ;
        return strcmp(a.name ,b.name )<0;

int main(){
    int n,m,k,amin,amax;
    for(int i=0;i<n;i++){
        scanf("%s %d %d",node[i].name ,&node[i].age ,&node[i].worth );
    for(int i=1;i<=k;i++){
        printf("Case #%d:\n",i);
        int cnt=0;
        for(int j=0;j<n;j++){
            if(node[j].age >=amin&&node[j].age <=amax){
                printf("%s %d %d\n",node[j].name,node[j].age ,node[j].worth );
            if(cnt==m) break;
        if(cnt==0) printf("None\n");
    return 0;

World's Worst Bus Schedule


DescriptionnnYou are a very impatient person, and hate to be kept waiting. You are on your way to visit a relative all the way in New Orleans. The problem is that the bus station you are at has the world's worst bus schedule! There are no arrival or departure times listed, only route durations for each bus running. Being the impatient person you are, you whip out your laptop and attempt to write a program that will determine how long you will have to wait before the next bus comes. Hey, you have nothing better to do, right?nInputnnInput to this problem will consist of a (non-empty) series of up to 100 data sets. Each data set will be formatted according to the following description, and there will be no blank lines separating data sets. nnnA single data set has 3 components: nnStart line - A single line, "START N", where N is the number of buses running and 1 <= N <= 20. nRoute Duration line - There will be N of these lines, and each line will consist of M route durations (where 1 <= M <= 10), which will signify how long it will take each bus to return to the bus station after completing a particular route. A route duration will be represented as an integer between 1 and 1000 (inclusive). nArrival Time - There will only be one of these lines per data set. This line represents the time that you arrived at the bus station and began waiting. This is simply the number of time units that you arrived at the bus station after the buses began running (all buses begin running at time 0). This number is represented as a positive integer (yes, it can be 0 as well, this would signify arriving at the bus station as the buses begin running). nEnd line - A single line, "END". nnFollowing the final data set will be a single line, "ENDOFINPUT". nOutputnnFor each data set, there will be exactly one line of output. This line will simply be the number of time units you will have to wait before the next bus comes after you arrive. You hate waiting so much that you will just get on the first bus that returns to the station. Let's hope this is the bus to New Orleans! nnNotes nnAll buses continuously go on their routes, starting back up with their first route after their last route is done. nIf the passenger's arrival time coincides with any of the bus' route departure times, he/she catches the bus at that time. nSample InputnnSTART 3n100 200 300n400 500 600n700 800 900n1000nENDnSTART 3 n100 200 300 4 3 2 4 2 22 n800n10 1000n32767nENDnENDOFINPUTnSample Outputnn200n20 问答