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>>stui.name;

cin>>stui.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);

ansm/2=stut.name;

//左边一列

int j=m/2-1;

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

ansj--=stui.name;

}

//右边一列

j=m/2+1;

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

ansj++=stui.name;

}

cout<<ans0;

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

cout<<" "<<ansi;

}

cout<<endl;

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

row--;

}

return 0;

}

相关推荐
a187927218317 分钟前
【算法】双指针与滑动窗口(三):相向双指针——比较、排除、收缩
算法·leetcode·双指针·滑动窗口·原理·相向双指针·算法讲解
代码王同学10 分钟前
2026.9.15日C++类和对象学习收获笔记
c语言·c++
刚入门的大一新生22 分钟前
Linux-简单设计libc库
linux·c++
AI 小老六26 分钟前
Agent 记忆系统难在取舍
人工智能·算法·架构·agent·memory·harness
大熊背28 分钟前
《Color constancy by characterization of illumination chromaticity》之色度色域最大化算法(一)
数码相机·算法·白平衡·色度色域
不会就选b29 分钟前
算法日常・每日刷题--<贪心>13
算法
带多刺的玫瑰42 分钟前
Leecode#35刷题之搜索插入位置
java·python·算法
我不会起名字3221 小时前
万字总结Golang入门项目
数据结构·经验分享·算法·golang·项目实战·复盘
6Hzlia1 小时前
【Classic 150 刷题计划】 LeetCode 14. 最长公共前缀 | C++ 纵向扫描法与防越界细节
c++·算法·leetcode
Niuguangshuo9 小时前
论文解读:CTC,端到端序列识别的开山之作
算法·语音识别