PAT (Advanced Level) Practise 1109. Group Photo (25) 结构体排序

「PAT乙级真题解析」Basic Level 1109 擅长C (问题分析+完整步骤+伪代码描述+提交通过代码) 题设给定26个英文字母的输出格式, 然后给定几个单词(由非大写英文字母隔开), 要求用给定的输出格式输出这些英文单词。 那么事情就简单了, 如果我们只看后半部分的话, 那基本就相当于`if char == 'A': print('A')`的级别了, 只是现在给定了各个英文字母的输出格式, 所以是`if word == "HELLO": print(指定格式("HELLO"))`。 所以重点在于将指定的输出格式存储下来, 然后在最后检查英文句子的时候输出. 阅读详情

1109. Group Photo (25)

时间限制
400 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

Formation is very important when taking a group photo. Given the rules of forming K rows with N people as the following:

  • The number of people in each row must be N/K (round down to the nearest integer), with all the extra people (if any) standing in the last row;
  • All the people in the rear row must be no shorter than anyone standing in the front rows;
  • In each row, the tallest one stands at the central position (which is defined to be the position (m/2+1), where m is the total number of people in that row, and the division result must be rounded down to the nearest integer);
  • In each row, other people must enter the row in non-increasing order of their heights, alternately taking their positions first to the right and then to the left of the tallest one (For example, given five people with their heights 190, 188, 186, 175, and 170, the final formation would be 175, 188, 190, 186, and 170. Here we assume that you are facing the group so your left-hand side is the right-hand side of the one at the central position.);
  • When there are many people having the same height, they must be ordered in alphabetical (increasing) order of their names, and it is guaranteed that there is no duplication of names.

Now given the information of a group of people, you are supposed to write a program to output their formation.

Input Specification:

Each input file contains one test case. For each test case, the first line contains two positive integers N (<=10000), the total number of people, and K (<=10), the total number of rows. Then N lines follow, each gives the name of a person (no more than 8 English letters without space) and his/her height (an integer in [30, 300]).

Output Specification:

For each case, print the formation -- that is, print the names of people in K lines. The names must be separated by exactly one space, but there must be no extra space at the end of each line. Note: since you are facing the group, people in the rear rows must be printed above the people in the front rows.

Sample Input:
10 3
Tom 188
Mike 170
Eva 168
Tim 160
Joe 190
Ann 168
Bob 175
Nick 186
Amy 160
John 159
Sample Output:
Bob Tom Joe Nick
Ann Mike Eva
Tim Amy John

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define PAUSE system("pause")

using namespace std;

const int maxn = 10000 + 10;

struct node {
	int h;
	char name[10];
	bool operator < (const node& on) const {
		if (on.h == h) {
			//return (int)name[0] < (int)on.name[0]; //debug 总是犯这种SB的错误(-.-)!
			return strcmp(name, on.name) < 0;
		}
		else {
			return h > on.h;
		}
	}
}p[maxn], ans[maxn];

int N, K;

void out(int len) {
	for (int i = 1; i <= len; i++) {
		printf(i == 1 ? "%s" : " %s", ans[i].name);
	}
	puts("");
}

int main()
{
	int row, lr, len, mid, cnt, i, j, cou;
	scanf("%d%d", &N, &K);
	row = N / K;
	lr = row + (N - row * K);
	if (N < K) {
		row = lr = 1;
	}
	for (int i = 1; i <= N; i++) {
		scanf("%s%d", p[i].name, &p[i].h);
	}
	sort(p + 1, p + 1 + N);

	cou = 1;
	for (int k = 1; k <= K; k++) {
		j = -1; i = 1;
		mid = (k == 1 ? lr : row) / 2 + 1;
		ans[mid] = p[cou++];
		cnt = 1;
		len = (k == 1 ? lr : row);
		while (cnt <= len && (mid + j >= 1 || mid + i <= len)) {
			if (mid + j >= 1) {
				ans[mid + j] = p[cou++];
				cnt++;
				j--;
			}
			if (mid + i <= len) {
				ans[mid + i] = p[cou++];
				cnt++;
				i++;
			}
		}
		out(cnt);
	}
	return 0;
}





1109 擅长C【PAT (Basic Level) Practice (中文)】 1109 擅长C【PAT (Basic Level) Practice (中文)】 阅读详情

相关推荐

HFSS仿真的后处理结果,如何根据天线表面的电流密度分布对天线进行优化?

在HFSS仿真中,天线表面的Jsurf​是最直观、最有价值的诊断工具之一。它不仅告诉你天线“能不能工作”,还能告诉你“为什么工作”以及“哪里出了问题”。

degogmy的博客 1156

PAT 甲级 1109 Group Photo

题意:给定一定人名字和高度,给他们拍照,拍照的要求是总共n个人,每排k个人,每排最多站n/k个人,其余站不下的人在较后面一排,每排排序的顺序是最高的站在中间,即m/2放最高人的名字,然后次高的站在左边,在次高的站在右边,即高的先站左边然后在站右边,每个依次进行,每排的高度都是大于前面一排人的高度的。 思路:用一个结构体数组保存每个人的信息,然后从高到低的顺序排序,设置每排人的数量,把最高的姓名放...

qq_42152681的博客 227

基于IP2369与STM32的45W双向PD移动电源设计

USB PD(Power Delivery)是一种面向高功率、智能协商的通用快充协议,其核心在于通过BMC编码在CC线上完成供电能力(PDO)动态匹配与电压/电流精准调控。IP2369作为高度集成的PD协议管理芯片,内置PHY、协议引擎与MOSFET驱动,可卸载MCU实时通信压力;而STM32F103系列凭借低功耗STOP模式与丰富外设,成为电源状态管理与用户交互的理想协处理器。该组合显著提升系统鲁棒性与能效比,适用于便携式移动电源、嵌入式备用电源及PD协议教学验证等场景。本文围绕IP2369配置电阻精度、

weixin_42608299的博客 515

【PAT】1109 Group Photo (25 分)

1109 Group Photo (25 分) 题目大意:给n个人排成k排,排列规则如下: 每排的人数必须为n/k(向下取整),多余的人排到下一排 后排所有人必须不矮于前排的任何人 每排都将最高的人安排在最中间(最中间为(m/2+1),m为那排的人数,结果要向下取整) 将人们按降序进入一排,然后按左右左右安排位置(For example, given five people with their heights 190, 188, 186, 175, and 170, the final format

SSibyl的博客 307

硬件开发实践:高速 PCB 差分信号与时钟同步优化

由两条互补信号线组成(正负极)接收端只关注两线之间电压差共模噪声对两线同时作用,可被抵消。

2501_93174775的博客 392

银河麒麟系统V10 sp1,安装wine 9.0

银河麒麟系统V10 sp1 x86_64,安装wine 9.0

daqinzl的专栏 1万+

PAT A1109 Group Graph C++解法

PAT A1109 参考代码

weixin_45203752的博客 379

【Unity游戏开发】SDK接入与集成——小白入门篇

一、简介   通常一款游戏开发到后期,一般都会涉及到第三方SDK的接入与集成,对于不熟悉SDK接入的同学来说,接SDK每次都是云里雾里,而熟悉SDK接入的同学又觉得不断地重复做接入SDK工作这样没有成就感,太尼玛无聊了(Android渠道一弄就十几个,直接吐血)。其实通常情况下接入SDK都是很简单的一个过程,本系列博客就让马三和大家从小白开始,从零基础开始学习如何接入SDK以及一些常见的SDK的...

weixin_34195142的博客 5763

1109 Group Photo(25分)

3、每排中高者站中间(中间位置为m/2+1,其中m为该排人数,除法向下取整);每排其他人以 间人为轴,按身高非增序,先右后左交替入队站在中间人的两侧(例如5人身高为190、188、186、 175、170,则队形为175、188、190、186、170。这里假设你面对拍照者,所以你的左边是中间人的右边);若多人身高相同,则按名字的字典序升序排列。先求出每排的人数,然后对整体排序,接着使用双端队列deque分别打印每排的序列。1、每排人数为N/K(向下取整),多出来的人全部站在后一排;

a131529的博客 341

libfacedetection 框架阅读及扩展经验

libfacedetection 框架源码解析与扩展心得1. libfacedetection 框架简介2. 源码解析2.1 facedetectcnn.h2.2 facedetectcnn.cpp2.3 facedetectcnn-model.cpp3. 其他层的扩展--depthwise convolution 前段时间因为工作需要,对libfacedetection框架做了些扩展,在阅读源...

weixin_42616332的博客 1500

ADRC自抗扰控制:工程抗扰“黑科技”,附C代码实战!

自抗扰控制(ADRC)是一种革新性的强鲁棒控制策略,通过主动估计和补偿系统扰动,无需精确数学模型即可实现优异控制性能。本文详细解析ADRC三大核心组件:跟踪微分器(TD)实现指令柔化,扩张状态观测器(ESO)实时估计总扰动,非线性状态反馈(NLSEF)完成动态补偿。针对二阶系统,文章提供完整的参数设计方法和C语言实现框架,包括关键函数fhan和fal的代码实现。ADRC将复杂对象"线性化"为积分器串联系统,显著提升抗扰能力,特别适用于电机控制、飞行器姿态等存在模型不确定性和强干扰的场景。

技术工作者 1730

PAT (Advanced Level) Practise 1109 Group Photo (25)

1109. Group Photo (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Formation is very important when taking a grou

Occult 741

DICOM医学影像开发者必备工具清单

PyDicom 是一个纯 Python 实现的 DICOM 文件解析库,允许开发者读取、修改和写入 DICOM 文件。它无需依赖外部库,易于集成到现有的 Python 项目中,非常适合快速开发和原型设计。DCMTK(DICOM Toolkit)是一个由OFFIS开发的开源C++库,提供了一整套DICOM标准的实现,包括文件操作、网络通信和图像处理等功能。它是开发高性能DICOM应用的理想选择。MicroDICOM 是一款免费的DICOM查看器,适用于Windows平台。

编程技术探索者,分享C/C++、C#、Java、数据库等开发经验,聚焦实战技巧与AI兴趣,助力编程爱好者成长。 577

【坑、逻辑】1109 Group Photo (25 分)

Formation is very important when taking a group photo. Given the rules of forming K rows with N people as the following: The number of people in each row must be N/K (round down to the nearest integer), with all the extra people (if any) standing in the la

weixin_45836276的博客 230

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

A1109. Group Photo (25| 逻辑题,附详细注释,逻辑分析)

写在前面 实现思路 结构体容器数组封装学生元数据信息 自定义比较函数 容器数组根据身高倒排后,分排 某一排,从原始数组中取第1位放中间 间隔顺序迭代放置左边、右边 具体代码 for(i=t+1; i<t+m; i=i+2) for(i=t+2; i<t+m; i=i+2) 打印输出当前排 注意输出格式,行末不得有多余空格 实现方案有难度,多练习,否则该类题目有...

kngines 477

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

1109. Group Photo (25)

1109. Group Photo (25) #include <iostream> #include <vector> #include <algorithm> #include <string> #include <map> using namespace std; struct pers...

areen7003的博客 134

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

PAT 1109 Group Photo(25 分)

Formation is very important when taking a group photo. Given the rules of forming K rows with N people as the following: The number of people in each row must be N/K (round down to the nearest inte...

Hickey_Chen的博客 553

PAT甲级——1109 Group Photo (排序)

1109Group Photo(25分) Formation is very important when taking a group photo. Given the rules of formingKrows withNpeople as the following: The number of people in each row must beN/K(round...

小熊猫的博客 474

PAT 1109(超简单双向队列解法)

PAT 1109 双向队列很简单,就多一个前加后加和前删后删的区别 直接上代码: #include <cstdio> #include <algorithm> #include <queue> #include <iostream> using namespace std; int N,K,cnt; struct person{ strin...

weixin_42129912的博客 342

PAT_A 1109. Group Photo (25)

pat 1109 Group Photo (25)

longtails的博客 1685

1109. Group Photo (25)-PAT甲级真题

1109. Group Photo (25) Formation is very important when taking a group photo. Given the rules of forming K rows with N people as the following: The number of people in each row must be N/K (round dow...

柳婼 の blog 2744

1109 Group Photo (25分)

1109Group Photo(25分) Formation is very important when taking a group photo. Given the rules of formingKrows withNpeople as the following: The number of people in each row must beN/K(round ...

chen_zan_yu_的博客 508

pat Deque(双端队列)

A “deque” is a data structure consisting of a list of items, on which the following operations are possible: Push(X,D): Insert item X on the front end of deque D. Pop(D): Remove the ...

weixin_30394333的博客 212
上一篇: PAT (Advanced Level) Practise 1107. Social Clusters (30) 并查集
下一篇: hdu4283 You Are the One 区间dp 记忆化搜索or递推
Daemoonn
博客等级 码龄11年 42粉丝 198原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值