AcWing 1599. 合影
原题链接
中等
作者:
你也想起舞吗
,
2020-07-24 09:44:53
,
所有人可见
,
阅读 662
#include <bits/stdc++.h>
using namespace std;
struct node{
int height;
string name;
};
node student2[100005];
void OutPut(int left,int right){
vector<int>v(right-left);
int mid=v.size()/2;
for (int i = left; i < right; ++i) {
int k=i-left;
if (k%2==1)
v[mid-(k+1)/2]=i;
else
v[mid+k/2]=i;
}
for (int i = 0; i < v.size(); ++i) {
printf("%s%s",i!=0?" ":"",student2[v[i]].name.c_str());
}
puts("");
}
bool cmp(const node&n1,const node&n2){
return n1.height!=n2.height?n1.height>n2.height:n1.name<n2.name;
}
int main(){
int N,K;
cin>>N>>K;
for (int i = 0; i <N ; ++i) {
cin>>student2[i].name>>student2[i].height;
}
sort(student2,student2+N,cmp);
int extra=N%K;
int M=N/K;
for (int i = 0; i < N; i+=M) {
if (i==0){
OutPut(0,M+extra);
i+=extra;
}
else
OutPut(i,i+M);
}
return 0;
}