标签:拍照 using 意思 函数 逻辑题 存储 main pre ==
#include<bits/stdc++.h>
using namespace std;
struct node{
int height;
string name;
};
int cmp(struct node a, struct node b){
return a.height != b.height ? a.height > b.height : a.name < b.name;
}
int main(){
int n, k, m;
cin >> n >> k;
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;
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 < m + t; 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;
}
标签:拍照 using 意思 函数 逻辑题 存储 main pre ==
原文地址:https://www.cnblogs.com/tsruixi/p/12934327.html