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;

}

相关推荐
研究点啥好呢5 分钟前
Momenta后端开发面试题精选:10道高频考题+答案解析(数据产线方向)
c++·python·面试·求职招聘
多加点辣也没关系18 分钟前
数据结构与算法|第十七章:贪心算法
数据结构·算法·贪心算法
多加点辣也没关系19 分钟前
数据结构与算法|第十四章:排序算法(上)— 比较类排序
数据结构·算法·排序算法
Hical6128 分钟前
C++26 前瞻心得:下一代 C++ 最值得期待的特性
c++
悲伤小伞29 分钟前
Linux_传输层协议TCP详解
linux·网络·c++·网络协议·tcp/ip
笨笨饿29 分钟前
#72_聊聊I2C以及他们的变体
linux·c语言·网络·stm32·单片机·算法·个人开发
机器人图像处理30 分钟前
6-自动白平衡(灰度世界算法)
opencv·算法·相机
Dr.Zeus37 分钟前
从电芯到系统:BMS算法视角下的电池热管理深度解析作者署名
算法·能源
ulias21240 分钟前
leetcode热题 - 6
linux·算法·leetcode
北顾笙98041 分钟前
day42-数据结构力扣
数据结构