PATA 1055: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 (≤10^5) the total number of people, and K (≤10^3)- 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^6,10^6] 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

思路分析:
步骤1:输入数据,结构数组peo存储输入n个人的信息,结构数组k存储K组待输出的信息;
步骤2:将peo结构数组按财富值排序(财富值相等时,年龄小的排前,财富值年龄均相等时名字字典序小的排前)
步骤3:考虑到年龄在(0,200]范围内,每个age对应的输出最大人数不超过100人,形成一个以age为下标的结构数组Age,Age.x为node1型vector,存储Age[age].num个人的信息
步骤4:重复K次调用函数fuc,用cnt[age]指针指向未输出的财富最大值的下标

#include"stdafx.h"
#include<vector>
#include<algorithm>
#include<string.h>
using namespace std;
const int maxn1 = 100005;
const int maxn2 = 10005;
const int maxn3 = 205;
struct node1 {
    char name[10];
    int age, net_worth;
}peo[maxn1];
struct node2 {
    int m, right, left;
}k[maxn2];
struct AGE {
    int num=0;
    vector<node1> x;
}Age[maxn3];
bool cmp(node1 a, node1 b) {
    if (a.net_worth != b.net_worth) return a.net_worth > b.net_worth;
    else if (a.age != b.age) return a.age < b.age;
    else return strcmp(a.name,b.name)<0;
}
void fuc(int a, int b,int mm) {
    int cnt[205] = { 0 },count=0;   //cnt[age]为未输出年龄为age的人财富值最大的下标
    for (int i = a; i <= b; i++) {  //年龄[a,b]范围内人数;
        count += Age[i].num;
    }
    if (count == 0) {
        printf("None\n");   //[a,b]区间无人输出NONE
        return;
    }
    if (count >= mm) count = mm;    //count>=mm时取mm,count<mm时输出count人
    for (int i = 0; i < count;i++) {
        int hh = a;
        while (Age[hh].num <= cnt[hh]) hh++;    //hh为未全部输出的年龄的最小值
        if (hh > b) return;     //hh超出[a,b]范围返回
        node1 max = Age[hh].x[cnt[hh]];     //初始化max
        int x = hh;     //初始化当前最大输出的年龄
        for (int j = a; j <= b; j++) {
            if (Age[j].num <= cnt[j]) continue;
            node1 temp = Age[j].x[cnt[j]];
            if (max.net_worth < temp.net_worth) {
                max = temp;     //修改最大值
                x = j;      
            }
        }
        cnt[x]++;       
        printf("%s %d %d\n", max.name, max.age, max.net_worth);
    }
}
int main()
{
    int n, K;
    scanf("%d %d",&n,&K);
    for (int i = 0; i < n; i++) {
        scanf("%s %d %d", &peo[i].name, &peo[i].age, &peo[i].net_worth);
    }
    sort(peo, peo + n, cmp);
    for (int i = 0; i < K; i++) {
        scanf("%d %d %d", &k[i].m, &k[i].left, &k[i].right);
    }
    for (int i = 0; i < n; i++) {
        if (Age[peo[i].age].num <= 100) {
            Age[peo[i].age].num++;
            Age[peo[i].age].x.push_back(peo[i]);
        }
    }
    for (int i = 0; i < K; i++) {
        printf("Case #%d\n", i+1);
        fuc(k[i].left, k[i].right, k[i].m);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
基于微信小程序的家政服务预约系统采用PHP语言和微信小程序技术,数据库采用Mysql,运行软件为微信开发者工具。本系统实现了管理员和客户、员工三个角色的功能。管理员的功能为客户管理、员工管理、家政服务管理、服务预约管理、员工风采管理、客户需求管理、接单管理等。客户的功能为查看家政服务进行预约和发布自己的需求以及管理预约信息和接单信息等。员工可以查看预约信息和进行接单。本系统实现了网上预约家政服务的流程化管理,可以帮助工作人员的管理工作和帮助客户查询家政服务的相关信息,改变了客户找家政服务的方式,提高了预约家政服务的效率。 本系统是针对网上预约家政服务开发的工作管理系统,包括到所有的工作内容。可以使网上预约家政服务的工作合理化和流程化。本系统包括手机端设计和电脑端设计,有界面和数据库。本系统的使用角色分为管理员和客户、员工三个身份。管理员可以管理系统里的所有信息。员工可以发布服务信息和查询客户的需求进行接单。客户可以发布需求和预约家政服务以及管理预约信息、接单信息。 本功能可以实现家政服务信息的查询和删除,管理员添加家政服务信息功能填写正确的信息就可以实现家政服务信息的添加,点击家政服务信息管理功能可以看到基于微信小程序的家政服务预约系统里所有家政服务的信息,在添加家政服务信息的界面里需要填写标题信息,当信息填写不正确就会造成家政服务信息添加失败。员工风采信息可以使客户更好的了解员工。员工风采信息管理的流程为,管理员点击员工风采信息管理功能,查看员工风采信息,点击员工风采信息添加功能,输入员工风采信息然后点击提交按钮就可以完成员工风采信息的添加。客户需求信息关系着客户的家政服务预约,管理员可以查询和修改客户需求信息,还可以查看客户需求的添加时间。接单信息属于本系统里的核心数据,管理员可以对接单的信息进行查询。本功能设计的目的可以使家政服务进行及时的安排。管理员可以查询员工信息,可以进行修改删除。 客户可以查看自己的预约和修改自己的资料并发布需求以及管理接单信息等。 在首页里可以看到管理员添加和管理的信息,客户可以在首页里进行家政服务的预约和公司介绍信息的了解。 员工可以查询客户需求进行接单以及管理家政服务信息和留言信息、收藏信息等。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值