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

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

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;
}





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

相关推荐

从零开始:H20服务器上DeepSeek R1 671B大模型部署与压力测试全攻略

最近,我有幸在工作中接触到了DeepSeek R1 671B模型,这是目前中文开源领域参数量最大的高质量模型之一。DeepSeek团队在2024年推出的这款模型,以其惊人的6710亿参数量和出色的推理性能,引起了业界广泛关注。作为一名AI基础设施工程师,我有机会在H20服务器上部署这个庞然大物,并对其进行了全面的压力测试。这篇文章将详细记录我的部署过程和性能测试方法,希望能为大家提供一些参考。💡为什么选择DeepSeek R1?超大规模参数量(671B)优秀的中英文理解能力开源可商用的许可证。

wangli的博客 1万+

PAT 甲级 1109 Group Photo

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

qq_42152681的博客 227

Python爬虫实战:避开巨潮资讯网反爬,稳定获取上市公司年报PDF下载地址

本文详细介绍了如何使用Python和Selenium突破巨潮资讯网的动态加载限制,稳定获取上市公司年报PDF下载地址。通过模拟真实用户操作、智能等待策略和反反爬虫技巧,帮助开发者高效爬取财经数据,适用于股票代码查询和年报分析等场景。

weixin_29065659的博客 1673

【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

多任务学习中的过拟合陷阱:动态停止训练机制详解与避坑指南

本文深入剖析了多任务学习中因任务过拟合不同步导致的性能下降问题,并详细介绍了动态停止-继续训练机制。该机制通过为每个任务设置独立的训练开关,基于验证集性能动态控制其梯度更新,有效缓解了任务间负迁移,是提升多任务模型整体泛化能力的关键策略。

happy2的博客 1096

【过检测】2026调试级去虚拟化虚拟机成品

EternalBlaze调试级虚拟机是由恒烈开发的定制化VMware环境,适用于逆向工程、病毒分析等专业场景。该虚拟机基于Windows 10 1909专业版,预装Python/JDK等开发环境和逆向工具包,支持快照回溯功能。特色包括:一键去虚拟化方案、双机调试支持、驱动开发环境等。适用场景涵盖CTF竞赛、软件调试、病毒行为分析等,但不支持DX12游戏和视频盗录。使用前需按步骤关闭安全中心、安装特定VMware版本并执行去虚拟化操作。虚拟机提供基础版和逆向调试增强版两种配置,均预装必要工具链。(149字)

Heng_lie的博客 2723

PAT A1109 Group Graph C++解法

PAT A1109 参考代码

weixin_45203752的博客 379

UDS服务应该支持哪些否定响应码

UDS服务应该支持哪些否定响应码所有服务都需支持的否定响应码具体的服务需要支持的否定响应码否定响应码定义及其取值 USD诊断服务的否定响应中包含有导致否定响应原因的编码,称为否定响应码(NRC, Negative Response Code)。否定响应码的取值范围为0x00 - 0xFF,被分为三组: 0x00:服务器内部实现否定响应码判断逻辑时使用,表示要给出肯定响应。 0x01 – 0x7F:诊断通信相关的否定响应码。 0x80 – 0xFF:服务器收到诊断服务请求时,由于某些条件不满足要求而给出的否定

闲聊汽车软件开发 4万+

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

【Agent从入门到实践】40 容错优化:异常处理、重试机制、降级策略

各位小伙伴,咱们的多Agent框架一路优化到现在,决策快、执行效率高、资源用得省,看似啥都行,但只要一遇到网络波动、工具故障、数据异常调用web_search工具时网络超时,整个检索任务直接失败,写作Agent没数据可用向量库连接异常,向量检索直接崩掉,依赖检索结果的Agent全趴窝单个Agent执行出错,整个并行任务流程直接中断,前功尽弃高并发下部分工具调用失败,框架没有备用方案,只能返回任务失败说白了,咱们之前的框架只有正常执行逻辑,没有异常兜底逻辑。

人工智能AI技术 917

【Qt开发】管理OpenGL上下文QOpenGLContext类及应用实践示例代码

QOpenGLContext 提供了一个简单、高效的接口来管理 OpenGL 上下文。本文详细介绍了 QOpenGLContext 的基本功能、常用方法、信号槽机制、高级应用技巧及常见问题的解决方法。通过这些介绍,读者可以更好地掌握和利用 QOpenGLContext 进行 OpenGL 渲染和管理实验。对于有特殊需求的开发者,也可以通过探索更多高级设置和优化策略,以满足具体的应用场景。

科技改变人类,技术成就未来 1879

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

【VTKExamples::Meshes】第十二期 QuadricDecimation

本文分享VTK样例QuadricDecimation,并解析接口vtkQuadricDecimation,希望对各位小伙伴有所帮助!

qq_40041064的博客 353

【坑、逻辑】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的博客 231

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

1109. Group Photo (25)

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

areen7003的博客 136

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

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 478

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 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_A 1109. Group Photo (25)

pat 1109 Group Photo (25)

longtails的博客 1685

PAT A1109 Group Photo(25 分)

1.这道题初看题意复杂,其实很简单的排序问题。 2.要注意用vector的时候一定不要多给,少给了会vector out of ....,但多给了不容易看出来,要多少给多少,我就是因为多给了导致排序出来得结果有两个空node 代码: #include&lt;iostream&gt; #include&lt;vector&gt; #include&lt;string&gt; #include&...

luoshiyong123的博客 347

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 2748
上一篇: 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、付费专栏及课程。

余额充值