排序 - PAT甲级 1025 PAT Ranking (25 分) C / C++

PAT甲级真题 1025 PAT Ranking (25分) C++实现(分段排序,合并后再总排序) 题目 Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in several places, and the ranklis... 阅读详情
#include<cstdio>
#include<algorithm>
#include<cstring>

using namespace std;

struct testee {
	char regis_num[15];
	int score;
	int final_rank;
	int local_num;
	int local_rank;
}testees[30010];

bool cmp(testee a, testee b) {
	if (a.score != b.score) return a.score > b.score;
	else return strcmp(a.regis_num, b.regis_num) < 0;
}

int main() {
	int total_num = 0, N, K, input_idx = 0;
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {// N是考场数
		int start_idx = input_idx, end_idx;
		scanf("%d", &K);
		total_num += K;
		for (int z = 0; z < K; z++) { // K是该考场考生数
			scanf("%s %d", &testees[input_idx].regis_num, &testees[input_idx].score);
			testees[input_idx].local_num = i + 1;
			input_idx++;
		}//输入某个区域的选手
		end_idx = input_idx;
		//立即局部排序
		sort(testees + start_idx, testees + end_idx, cmp);
		int local_rank = 0;
		for (int j = start_idx; j < end_idx; j++, local_rank++) {
			if (j == start_idx) {
				testees[j].local_rank = 1;
				continue;
			}

			if (testees[j].score != testees[j - 1].score) testees[j].local_rank = local_rank + 1;
			else testees[j].local_rank = testees[j - 1].local_rank;
		}
	}
	//整体排序
	sort(testees, testees + total_num, cmp);
	for (int j = 0; j < total_num; j++) {
		if (j == 0) {
			testees[j].final_rank = 1;
			continue;
		}
		if (testees[j].score != testees[j - 1].score) testees[j].final_rank = j + 1;
		else testees[j].final_rank = testees[j - 1].final_rank;
	}
	//输出
	printf("%d\n", total_num);
	for (int i = 0; i < total_num; i++) {
		printf("%s %d %d %d\n", testees[i].regis_num, testees[i].final_rank, testees[i].local_num, testees[i].local_rank);
	}

	return 0;

}

初次使用sort函数对结构体进行排序,还是有很多细节的地方需要注意。【排名从小到大,则分数由高到低】

1. sort函数传入的参数是地址, &a[10]

2.存储13位的考生号的时候,可以用long long, 但是遇到00000003这种情况没法处理,所以使用char[15]来存储可以保持原貌; 然后使用strcmp函数进行比较 【这也是测试点3的考察点】

3.scanf输入的时候,全局索引input_dix,局部z,不要用z输入

4.local_rank,保证每一种情况都能++,放在for里

相关推荐

解锁SPWM电压利用率:三次谐波注入幅值的黄金分割点

本文深入探讨了SPWM电压利用率的提升方法,重点介绍了三次谐波注入技术及其黄金分割点(1/6比例)。通过数学推导和工程实践,揭示了如何通过特定幅值的三次谐波注入将电压利用率从86.6%提升至115%,与SVPWM相当。文章还提供了实验室调试流程和DSP实现代码,帮助工程师优化逆变器设计。

weixin_30729609的博客 916

1025 PAT Ranking——C/C++

Question 1025 PAT Ranking (25 point(s)) Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneo...

吉大秦少游 676

SAP BTP开发入门:从PaaS到CAP/UI5的30天学习路线

在云计算与数字化转型的大背景下,企业系统集成与云端扩展需求激增,传统的单点开发模式正面临深刻变革。PaaS(平台即服务)作为云原生的核心概念,将基础设施、开发环境与应用服务统一封装,为企业提供了灵活的扩展能力。SAP BTP正是SAP生态中的PaaS平台,它承载着系统集成、低代码开发、AI服务与数据管理,成为连接S/4HANA等核心业务系统与创新应用的桥梁。对于ABAP开发者而言,掌握BTP不仅是技能升级,更是应对从传统部署向云端订阅模式转型的必由之路。本文从平台基础出发,梳理BTP的核心服务与开发模型(如

weixin_31766003的博客 285

[C/C++] 1025 PAT Ranking(25 分)

1025 PAT Ranking(25 分) Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in several pla...

dulongxiang の blog 630

Oracle到金仓数据库信创改造迁移实施规划方案

**性能测试和优化**:对金仓数据库的性能进行测试,根据业务负载情况进行必要的调优,确保系统能够稳定高效运行。- **数据兼容性**:评估Oracle数据库中的数据结构和金仓数据库的兼容性,明确需要重构的数据模型。- **性能测试**:通过对金仓数据库的性能测试,预估在实际业务环境下的表现,是否能达到业务需求。- **工具选择**:选择适合的迁移工具,如金仓数据库提供的迁移工具,能够提升迁移效率和准确性。- **全面迁移**:在初步迁移成功后,进行全面数据迁移,确保所有数据完整迁移到金仓数据库上。

hdrhdrjdididrr的博客 482

SpringBoot多线程查询实战-查询库中所有数据多线程实现

但是,在数据量较大且服务器资源足够的情况下,多线程方法通常能够显著提高查询效率。此外,由于它是同步执行的,没有利用并行处理的能力,所以在处理大量数据时可能会比较慢。这个方法采用了分页查询的方式,每次只获取一部分数据,从而避免了内存溢出的问题。然而,它也是同步执行的,没有利用多线程或并行处理的能力。如果每次分页查询的数据量仍然很大,或者需要查询的轮数很多,那么这种方法的效率可能仍然会受到限制。​ ​ ​在比较这三种方式的效率时,我们需要考虑几个关键因素:数据量的大小、查询操作的复杂性、以及并行处理的能力。

勇敢牛牛,不怕困难! 4809

PAT (Advanced Level) Practice 1025 PAT Ranking (25 分)

Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in several places, and the ranklists w...

zamaochick的博客 326

快充协议全兼容!HUSB390对比测试:iPhone/小米/华为哪个充电最快?

本文深入评测了HUSB390快充协议芯片的全兼容性能,展示了其在iPhone、小米和华为设备上的极速充电表现。通过智能功率分配算法和多协议并行处理引擎,HUSB390实现了高效的动态调压和温度控制,显著提升多设备充电效率。特别适合需要同时为不同品牌设备快充的用户。

dd012的博客 1万+

pat 1025

1025. PAT Ranking (25) 时间限制 200 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Programming Ability Test (PAT) is organized by the College of C

suichen1的专栏 775

SAP S4业务伙伴(BP)实战指南:从角色分配到数据同步的完整流程

本文详细解析了SAP S4业务伙伴(BP)功能,从基础概念到实战操作,涵盖角色分配、数据同步及常见问题排查。通过BP机制,企业可高效管理客户、供应商等多重身份,实现数据共享和动态切换,显著提升主数据管理效率。特别适合SAP实施顾问和ERP管理员参考。

y2z3a4b5c的博客 870

弱网、高热、只有 32MB 内存:恶劣环境下嵌入式 SoC 音视频开发的“不死”法则

永远不要假设。你申请一个 1920 宽的图像,硬件为了对齐(比如 16 字节对齐或 256 字节对齐),实际分配的一行可能有 1936 甚至是 2048 字节。那个多出来的部分叫Padding。如果你写代码时用来计算数据量,或者用Width来做指针偏移:恭喜你,你的画面会像被风吹歪的百叶窗一样,产生斜切畸变。永远使用VB_CONF结构体里返回的u32Stride字段。这是区分新手和老手的试金石。第六章 ISP 调优(Tuning)实战:为什么你调出的画面像个“鬼片”?

大模型大数据攻城狮的专栏 1770

PAT Ranking (排名)

PAT Ranking (排名) Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in several pla...

weixin_30772105的博客 316

YOLOV8改进:添加Wiseiou,有效涨点

【代码】YOLOV8改进:添加Wiseiou,有效涨点。

AIcurator的博客 2393

PAT A1025 PAT Ranking (25分)

PAT甲级:A1025 PAT Ranking (25 分) Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in seve...

只想用最简短的代码刷题 130

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

【PAT甲级 补全前导0 vector作为函数参数】1025 PAT Ranking (25 分) Java、C++

如何补全前导0 Java String idStr = String.format("%013d", out.id); //用0补全13位 System.out.println(idStr); C++ printf("%013lld", out.id); //用0补全13位 容器vector在函数中的参数传递 (1)值传递: 形参改变不影响实参 void fun(vector<...

寒泉 2万+

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

PAT甲级1025 PAT Ranking:[C++题解]排序、结构体、排名

刷题

阿正的梦工坊 613

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

PAT甲级.1025. PAT Ranking (25)

题目 Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in several places, and the ranklists

R11happy的博客 420

【个人代码及思路】PAT甲级:1025 PAT Ranking (25分)

PAT (Advanced Level) Practice 1025 PAT Ranking (25分) Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in several places, and the ranklists will

一只小杰鸽的博客 177

PTA 甲级1025 PAT Ranking

Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in several places, and the ranklists w...

weixin_44211856的博客 220

PAT甲级 1025 PAT Ranking (25分) (题目 + 代码 + 详细注释)

Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in several places, and the ranklists w...

470

PAT_甲级_1025 PAT Ranking (25分) (C++)【签到题】

目录 1,题目描述 题目大意 输入 输出 2,思路 数据结构 3,代码 1,题目描述 Sample Input: 2 5 1234567890001 95 1234567890005 100 1234567890003 95 1234567890002 77 1234567890004 85 4 1234567890013 65 1234567890011 25 123...

&再见萤火虫&的博客 295

PAT甲 1025-PAT Ranking(汉译)

PAT甲 1025-PAT Ranking(汉译) 题目描述: 程序设计能力测验是由浙江大学计算机科学与技术学院组织的。每个测试应该在多个地方同时运行,排名表将在测试后立即合并。现在你的工作是编写一个程序来正确合并所有排名表并生成最终的排名。 输入: 每个输入文件包含一个测试用例。对于每种情况,第一行包含一个正数N(≤100),即测试位置的数量。接着是N个排名表,每一个都以一个包含正整数K(≤300)的行开始,K行包含被测者的注册号(13位数字)和每个被测者的总分。一行中的所有数字都用空格隔开。 输出: 对

在成为一名合格的程序员的道路上蹒跚前行 233

PAT 甲级 1025 PAT Ranking (25)(25 分)

1025 PAT Ranking (25)(25 分) Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in severa...

宝付支的博客 287

PTA甲级 1025 PAT Ranking (C++)

Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in several places, and the ranklists will be merged immediately after the test. Now it is your

Misdirection 163

1025. PAT Ranking (25)(C++)

Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in several places, and the ranklists w...

qq_41562704的博客 258

PAT (Advanced Level) Practice A1025 PAT Ranking (25 分) (C++)(甲级)

1025 PAT Ranking (25 分) Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in several pla...

izhxxx的博客 235
上一篇: LeetCode 9. Palindrome Number - C++
下一篇: 一些比较难懂的递归题目 c++
DedicateToAI
博客等级 码龄9年 6粉丝 90原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值