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;

}

相关推荐
Ivanqhz9 分钟前
MoE 原理、TC/EC 路由、LSH-MoE 与负载均衡浅析
运维·网络·人工智能·深度学习·算法·机器学习·负载均衡
Sarvartha12 分钟前
栈的四则运算、栈的递归应用
数据结构·算法
stolentime18 分钟前
CF2277E Tree Guessing题解
c++·算法·贪心算法·交互·ad-hoc
逐光者93334 分钟前
杨氏模量:从定义到工程应用
算法
syagain_zsx1 小时前
ODB 与 MySQL:C++ 里的 ORM 实践(类即表、事务铁律与查询封装)
开发语言·数据库·c++·mysql·工具库·1024程序员节
小鱼仙官1 小时前
使用Qt封装C/C++ 动态库 用于第三方调用
c语言·c++·qt
荆棘鸟智能2 小时前
扬尘在线监测数据接入与异常清洗:从断点补传到质量审计
人工智能·算法·系统架构
晚风予卿云月2 小时前
【C++高并发内存池】 1.定长内存池的实现
开发语言·c++·内存管理
动词ing2 小时前
【题目练习】旋转图像
算法
天疆说2 小时前
【无标题】
算法