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;

}

相关推荐
To_OC6 小时前
LC 128 最长连续序列:别上来就排序,O (n) 解法才是这题的灵魂
javascript·算法·leetcode
刘马想放假18 小时前
Modbus 全栈技术解析:TCP、RTU、ASCII、RTU over TCP
数据结构·网络协议
05Kevin19 小时前
lk每日冒险题--数据结构6.27
算法
To_OC1 天前
从一次栈溢出报错说起,我把递归彻底扒明白了
javascript·算法·程序员
千纸鹤安安1 天前
千问Qwen-AgentWorld来了:一个语言模型搞定七大Agent场景,GPT-5.4都输了
算法
七牛开发者2 天前
MCP 到底是什么?为什么 Agent 都想接上它
算法·aigc·agent
北域码匠2 天前
冒泡排序太慢?鸡尾酒排序双向优化,原生 C# 零第三方库完整代码
数据结构·排序算法·泛型·c# 算法·鸡尾酒排序·原生 c# 开发·冒泡排序优化·嵌入式算法