首页 > 其他分享 >世界首富

世界首富

时间:2022-08-24 13:59:21浏览次数:47  
标签:const name ages int 首富 age 世界 include

https://www.acwing.com/problem/content/1543/

#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>

using namespace std;

const int N = 210;

int n, m;
struct Person
{
    string name;
    int age, w;

    bool operator< (const Person& t) const
    {
        if (w != t.w) return w > t.w;
        if (age != t.age) return age < t.age;
        return name < t.name;
    }
};

vector<Person> ages[N];
int idx[N];

int main()
{
    scanf("%d%d", &n, &m);

    char name[10];
    for (int i = 0; i < n; i ++ )
    {
        int age, w;
        scanf("%s%d%d", name, &age, &w);
        ages[age].push_back({name, age, w});
    }

    for (auto& age : ages) sort(age.begin(), age.end());

    for (int C = 1; C <= m; C ++ )
    {
        printf("Case #%d:\n", C);
        int cnt, a, b;
        scanf("%d%d%d", &cnt, &a, &b);

        memset(idx, 0, sizeof idx);
        bool exists = false;
        while (cnt -- )
        {
            int t = -1;
            for (int i = a; i <= b; i ++ )
                if (idx[i] < ages[i].size())
                {
                    if (t == -1 || ages[i][idx[i]] < ages[t][idx[t]])
                        t = i;
                }

            if (t == -1) break;
            auto& p = ages[t][idx[t]];
            idx[t] ++ ;

            printf("%s %d %d\n", p.name.c_str(), p.age, p.w);
            exists = true;
        }

        if (!exists) puts("None");
    }

    return 0;
}

标签:const,name,ages,int,首富,age,世界,include
From: https://www.cnblogs.com/xjtfate/p/16619622.html

相关文章

  • 013:魔兽世界之一:备战
    (21条消息)C++编程练习013:魔兽世界之一:备战_德林恩宝的博客-CSDN博客1#include<iostream>2#include<cstdio>3#include<cstring>4usingnamespaces......
  • D3D世界变换
    首先讲解一下模型空间什么是模型空间呢?每个模型(3D物体)都有它自己的空间,空间的中心(原点)就是模型的中心。在模型空间里,只有模型上的不同点有位置的相对关系。那什么是世界空......
  • 攻防世界 | Web-ics-05
    题目描述其他破坏者会利用工控云管理系统设备维护中心的后门入侵系统打开题目先进来随便点点看看有什么功能 除了“设备维护中心”,其他都没反应,对应了题目,那么应......
  • 攻防世界 | Web-Cat
    本题涉及到的知识点有很多:1.cURL的post文件上传2.php的curl上传组件3.python的字符编码4.django的框架知识解题步骤 先按照它的要求随便输入一个域名: 是一......
  • 攻防世界 | Web-Fakebook
    这关一进来一个登录框,一个注册框,题目没给什么提示先注册一个试试(但是注册完之后退不回去了需要重新开一个浏览器)注册完随便点一点,发现URL有点异样http://111.200.241.......