PAT A1055. The World's Richest (25)

Mmdetection用自己的数据集训练Mask_RCNN 将自己数据的标签写入配置文件,在data前一行添加自己的标签列表,同时在train,val,test中添加classes = classes,如果不添加,模型就会默认读取coco原始数据集的80个标签,与自己的数据集对应不上就会报错。2.打开第二个文件coco_instance.py,将data_root路径改为你自己coco数据集的位置(注意一定要以/结尾),修改输出图片尺寸(根据自己的数据集决定)3.将标注完的数据转为Mask_rcnn训练所需的数据集格式。4.将数据集放到训练代码文件夹中。 阅读详情

题目链接

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

本题虽然简单,但是不能忽视其陷阱。

在第二审查点的时候,运行时间会提高,到达207ms,但不会超时(<=400ms)。原代码如下:

#include<cstdio>
#include <algorithm>
#include<cstring>
using namespace std;
struct Del {
    char name[10];
    int age, worth;
};
Del del[100005];
bool cmp(Del a, Del b) {
    int s = strcmp(a.name, b.name);
    if(a.worth!=b.worth)return a.worth > b.worth;
    else if (a.age != b.age)return a.age < b.age;
    else return s < 0;
}
int main() {
    int n, k;
    scanf("%d %d", &n, &k);
    for (int i = 0; i < n; i++) {
        scanf("%s %d %d", del[i].name, &del[i].age, &del[i].worth);
    }
    sort(del, del + n, cmp);
    for (int i = 0; i < k; i++) {
        int m, amin, amax;
        scanf("%d %d %d", &m, &amin, &amax);
        int cnt = 0,age;
        printf("Case #%d:\n", i + 1);
        for (int j = 0; j < n; j++) {
            if (cnt == m)break;
            age = del[j].age;
            if (age >= amin&&age <= amax) {
                printf("%s %d %d\n", del[j].name, age, del[j].worth);
                cnt++;
            }
        }
        if (cnt == 0)printf("None\n");
    }
    return 0;
}

但是算法笔记上面运行时间要求在200ms以内。所以按照书上的思想,将数组进行了预处理,复杂度得到降低,结果在检查点2所得到的结果是150ms,其余各检查点也都有所降低,代码修改如下:

#include<cstdio>
#include <algorithm>
#include<cstring>
using namespace std;
struct Del {
    char name[10];
    int age, worth;
};
int age[100005];
Del del[100005],ano[100005];
bool cmp(Del a, Del b) {
    int s = strcmp(a.name, b.name);
    if(a.worth!=b.worth)return a.worth > b.worth;
    else if (a.age != b.age)return a.age < b.age;
    else return s < 0;
}
int main() {
    int n, k;
    scanf("%d %d", &n, &k);
    for (int i = 0; i < n; i++) {
        scanf("%s %d %d", del[i].name, &del[i].age, &del[i].worth);
    }
    sort(del, del + n, cmp);
    int num = 0;
    for (int i = 0; i < n; i++) {
        if (age[del[i].age] <= 100) {
            age[del[i].age]++;
            ano[num++] = del[i];
        }
    }
    for (int i = 0; i < k; i++) {
        int m, amin, amax;
        scanf("%d %d %d", &m, &amin, &amax);
        int cnt = 0,age;
        printf("Case #%d:\n", i + 1);
        for (int j = 0; j < num; j++) {
            if (cnt == m)break;
            age = ano[j].age;
            if (age >= amin&&age <= amax) {
                printf("%s %d %d\n", ano[j].name, age, ano[j].worth);
                cnt++;
            }
        }
        if (cnt == 0)printf("None\n");
    }
    return 0;
}

增加了控制每个年龄个数的数组age。由于m<=100,所以,只需要将每个年龄上的前100名计入ano结构体数组中即可。此时,当n到达100000时,代码在经过检查点的时候,不会像第一个代码那样,遍历100000次,而是遍历20000次,有效降低了查询时的复杂度,同时也让我得到了宝贵的经验。


保姆级教程:用GMT6.1绘制专业地形起伏图(从数据下载到出图避坑) 本文提供了一份详细的GMT6.1绘制地形起伏图的保姆级教程,从环境搭建到数据下载,再到核心绘图命令解析,帮助用户避开常见错误。特别适合科研人员和地理信息爱好者快速掌握专业地形图的绘制技巧,提升工作效率。 阅读详情

相关推荐

C++控制台实现简单的注册登录

C++控制台实现简单的注册登录 #include<iostream> #include<string> #include <vector> #include <conio.h> void Display();//调用display显示switch()界面 void Register();//注册 void Enter();//登录 using nam...

乔路非 2万+

PAT A1055(运行超时)

只要减少sort函数的使用即可通过测试点2,如下 只使用一次sort()函数。 #include<iostream> #include<algorithm> #include<cstring> #include<vector> using namespace std; const int maxn = 100010; struct Person{ char name[10]; int age, worth; }person[maxn]; vector.

学习笔记,不喜勿喷! 136

手把手教你用Nangate 45nm开源工艺库搞定数字电路仿真(附FreePDK资源)

本文详细介绍了如何使用Nangate 45nm开源工艺库进行数字电路仿真,包括环境搭建、关键文件解析、仿真环境配置及低功耗设计等实战内容。特别推荐FreePDK资源,帮助读者快速掌握从理论到实践的全流程操作,适用于学术研究和小规模数字电路设计。

weixin_30352645的博客 490

PAT——A1055(排序)

题目链接: #include&lt;cstdio&gt; #include&lt;iostream&gt; #include&lt;cmath&gt; #include&lt;cstring&gt; #include&lt;algorithm&gt; using namespace std; #define maxn 100010 struct person{ char name[10...

ZMST的博客 260

(八)基于MuJoCo的LeRobot SO100仿真操控实战指南(操作优化)

本文详细介绍了如何在MuJoCo仿真环境中搭建并优化LeRobot SO100机械臂的操控。通过两种核心模式(纯键盘仿真与实机镜像同步)的实战演示,重点讲解了关键的参数标定方法,以实现虚拟模型与真实硬件的精准同步。文章还提供了性能优化技巧,旨在帮助开发者构建高效、安全的机器人算法开发与测试流程。

weixin_29083649的博客 320

PAT 自学题解 A 1055【测试点1,2】

测试点段错误qaq,有没有大佬帮忙看一下 #include<cstdio> #include<iostream> #include<cstring> #include<algorithm> using namespace std; struct ID//人员 { char name[50]={0}; int age=0,worth=0; }id[12000],temp[12000]; struct query//问题 { int .

weixin_54868899的博客 455

内存设计指南:01 Xilinx DDR4 design guide解析

最近有很多网友咨询FPGA DDR4为什么速率总是上不去的问题,发现他们的设计确实很随意,都没有遵守一些手册的基本要求,所以今天和大家一起重新读一读DDR4 design guide,看看哪些要求是一定不能忽略的。首次设计一款新的芯片或者内存方案时,可能会无从下手。对于内存设计,官方指导首推JEDEC规范,每一代内存推出时,在JEDEC官网均能找到对应的规范文档、各种内存形式的说明文档如DDR4-JESD79、DDR4 SDRAM UDIMM Design Specification以及内存条DEMO等。

halee_00的博客 3302

C++题解PAT A1055 The

一定要先排序,然后找到你年龄范围,主要的核心也没啥(j<n) && (num<m)这句话要注意,也就是输出人的数量一定比总人小,统计的数量不能大于输出的数量

执念斩长河 807

ROS & ROS2 机器人深度相机激光雷达多传感器标定工具箱入门教程(一)

multisensor_calibration 是一个积极维护的通用标定工具箱,用于辅助基于目标的多传感器标定,支持 ROS 1 和 ROS 2。它提供了多种方法和应用来标定复杂的多传感器系统,例如。

2506_90492529的博客 3262

探索如何利用CST和ADS进行DDR的SIPI联合仿真

本文系统介绍了CST和ADS两款工具进行DDR信号完整性/电源完整性(SI/PI)联合仿真的方法。CST采用工作室协同方式,通过PCB布局导入、材料设置、模型分配等步骤,重点分析了电源阻抗优化和信号波形质量。ADS则利用SIPro、PIPro等专用工具,突出系统级验证和自动化优化功能。两者各有优势:CST擅长3D结构精确建模,ADS更适于快速系统验证。文章建议可根据项目需求混合使用两种工具,并提供了模型简化、频带选择等实用技巧。通过对比分析,为工程师选择仿真工具提供了决策参考。

一只豌豆象的博客 1150

PAT a1055题解

#include #include #include using namespace std; int Age[100010] = {0}; struct Person{ int age, worths; char name[10]; }ps[100010], valid[100010]; bool cmp(Person a, Person b){ if(a.worths !=

Tang's学习笔记 786

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

PAT A1055 The World's Richest (25 分) 排序

题目大意:给出N个人的姓名、年龄和资产信息,要求输出在指定年龄区间内最富有的M个人的信息。 按照资产排序后,直接暴力遍历所有人的信息,符合年龄要求的输出,并维护已经输出的数量<=M即可。不过这样测试点2耗时会比较长,题目似乎更改了时间限制,按照以前的200ms的时间限制需要换一种思路,即一开始就要将每个年龄的前M个人单独存放到数组里,查询的时候从这个数组里查询。不过既然放宽...

HackingGate的博客 166

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

1055 The World's Richest (25 分)——PAT A

1055The 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, ...

weixin_42769575的博客 150

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

PAT A1055 The World's Richest (25分)

题目链接:https://pintia.cn/problem-sets/994805342720868352/problems/994805421066272768 题目描述 Forbes magazine publishes every year its list of billionaires based on the annual ranking of the world’s wealthi...

Rhao的博客 266

PAT A 甲级 1055 The World's Richest (25分)

1055 The World’s Richest (25分) 吐槽 又是试了两种办法。然后才知道为啥有两个超时测点。我这两个方法擅长的测点正好不同。 思路 试了两种办法,一个测点1概率过测点2必过,另一个测点1必过测点2一直不过。 前者是一次排序,然后每次遍历所有人找出相应数量的符合年龄大小的人。 后者是先将所有人按年龄排序,然后每次找出那个年龄区间内的人(它们是相邻的),按worth排序/放进新...

虚境的博客 276

PAT_A 1055. The World's Richest (25)

1055. The World’s Richest (25) 排序

longtails的博客 637

PAT甲级A1055 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 peopl...

vir_lee的博客 289

PAT-A 1055 The World's Richest (25 分)

思路:先将所有的富人按照给定要求进行排序,在每次查询时,遍历富人,如果年龄合适,则输出,并更新已经输出的数量,如果输出的数量达到了要求,则停止输出。

qq_38127801的博客 175

PAT A 1055 The World's Richest (25分)

一、思路 将全部记录按要求排序; 对于每个请求,遍历全表,若年龄符合要求则输出,注意输出不多于M个,且输出为0时输出None; 测试点2超时:使用scanf()、printf()输入输出; 二、代码 #include <cstdio> #include <string> #include <vector> #include <algorithm> u...

Siumai's Blog 137

PAT A1055 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 ...

weixin_30512089的博客 173

PAT A1055 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 peopl...

fried123123的博客 235

PAT A1055 the world's richest(25)

从头到尾遍历 万幸没有超时。晴神书里的写法是有优化 #include #include #include using namespace std; struct man{ char name[10]; int age; int worth; }men[100005]; int cmp(man a,man b){ if(a.worth!=b.worth) ret

momottyy的专栏 342

PAT-A1055. The World's Richest (25)(排序)

整个排序后遍历。#include #include #include #include #include using namespace std; #define MAX 100000+10 struct People { char name[10]; int age; int networth; } people[MAX]; int cmp(const vo

WJ的专栏 362
上一篇: PAT A1028. List Sorting (25)
下一篇: PAT A1075. PAT Judge (25)
DemonInside
博客等级 码龄10年 1粉丝 18原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值