1109 Group Photo

#include<iostream>

#include<vector>

#include<algorithm>

using namespace std;

int n,k;

struct node{

string name;

int height;

};

bool cmp(struct node a,struct node b){

return a.height!=b.height?a.height>b.height:a.name<b.name;

}

int main(){

cin>>n>>k;

int m;

vector<node>stu(n);

for(int i=0;i<n;i++){

cin>>stu[i].name;

cin>>stu[i].height;

}

sort(stu.begin(),stu.end(),cmp);

int t=0,row=k;//t是已处理的学生索引

//计算每行人数

while(row){

if(row==k){

m=n-n/k*(k-1);

}else{

m=n/k;

}

vector<string>ans(m);

ans[m/2]=stu[t].name;

//左边一列

int j=m/2-1;

for(int i=t+1;i<t+m;i=i+2){

ans[j--]=stu[i].name;

}

//右边一列

j=m/2+1;

for(int i=t+2;i<t+m;i=i+2){

ans[j++]=stu[i].name;

}

cout<<ans[0];

for(int i=1;i<m;i++){

cout<<" "<<ans[i];

}

cout<<endl;

t=t+m;//移动到下一批学生

row--;

}

return 0;

}

相关推荐
CoovallyAIHub4 分钟前
YOLO-Maste开源:首个MoE加速加速实时检测,推理提速17.8%!
深度学习·算法·计算机视觉
清铎8 分钟前
leetcode_day13_普通数组_《绝境求生》
数据结构·算法
_OP_CHEN10 分钟前
【从零开始的Qt开发指南】(二十)Qt 多线程深度实战指南:从基础 API 到线程安全,带你实现高效并发应用
开发语言·c++·qt·安全·线程·前端开发·线程安全
hetao173383718 分钟前
2026-01-09~12 hetao1733837 的刷题笔记
c++·笔记·算法
fqbqrr21 分钟前
2601C++,模块导出分类
前端·c++
say_fall33 分钟前
泛型编程基石:C++ 模板从入门到熟练
java·开发语言·c++·编辑器·visual studio
txinyu的博客39 分钟前
结合游戏场景解析UDP可靠性问题
java·开发语言·c++·网络协议·游戏·udp
郝学胜-神的一滴1 小时前
深入解析Mipmap层级判定原理:从理论到实践
c++·unity·godot·游戏程序·图形渲染·unreal engine
雾岛听蓝1 小时前
探索C++继承机制
开发语言·c++
过河卒_zh15667661 小时前
情感型AI被“立规矩”,AI陪伴时代进入下半场
人工智能·算法·aigc·生成式人工智能·算法备案