#include<cstdio>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
struct person
{
string name;
int height;
}p[10010];
bool cmp(person a, person b)
{
if (a.height != b.height) return a.height > b.height;
else return a.name < b.name;
}
int main()
{
int n, k;
scanf("%d%d", &n, &k);
for (int i = 0; i < n; i++)
{
cin>> p[i].name>>p[i].height;
}
sort(p, p + n, cmp);
int rownum = round(n / k);//每排人数
int lastrow = n - (k - 1)*rownum;//最后一排人数
int row = k,t=0;
while (row)
{
int m;
if (row == k) m = lastrow;
else m = rownum;
vector<string> s(m+1);
int mid = round(m / 2) + 1;
s[mid] = p[t].name;
int h1 = mid-1, h2 = mid+1;
for (int i = t + 1; i < t + m; i += 2)//向左排序
{
s[h1--] = p[i].name;
}
for (int i = t + 2; i < t + m; i += 2)//向右排序
{
s[h2++] = p[i].name;
}
cout << s[1];//这里使用round之后排序实际是序号为1的放入了最左边的元素
for (int i = 2; i <= m; i++) cout << " " << s[i];
cout << endl;
t += m;
row--;
}
return 0;
}
A1109 Group Photo (25 分)
最新推荐文章于 2021-12-24 15:49:31 发布