题意:n个人,要拍成k行排队,每行 n/k人,多余的都在最后一排。

从第一排到最后一排个子是逐渐增高的,即后一排最低的个子要>=前一排的所有人

每排排列规则如下:

1.中间m/2+1为该排最高;

2.其他人按各自降序顺序,轮流排到中间最高的左边和右边;

举个例子 190 188 186 175 170

— — 190 — —

— 188 190 — —

— 188 190 186 —

175 188 190 186 —

175 188 190 186 170

3.当个子一样高时,名字按字典序顺序,靠前的先排入队伍。

纯粹模拟,没啥好说的。

#include <iostream>
#include <cstdio>
#include <string.h>
#include <algorithm>
using namespace std;
const int maxn=+; struct People{
char str[];
int height;
bool operator<(const People tmp)const{
if(height==tmp.height){
if(strcmp(str,tmp.str)<)
return false;
else
return true;
}
else{
return height<tmp.height;
}
}
}people[maxn];
int main()
{
int k,n;
scanf("%d %d",&n,&k);
int ans[k+][maxn];
int cols[k+];
for(int i=;i<n;i++){
scanf("%s %d",people[i].str,&people[i].height);
}
sort(people,people+n); int m=n/k;
int left,right;
for(int i=;i<=k;i++){
left=(i-)*m;
right=i*m-;
if(i==k){
m=n-(k-)*m;
right=n-;
}
cols[i]=m;
int center=m/+;
int idx=right;
ans[i][center]=idx;
idx--;
int l=center-,r=center+;
while(r<=m){
ans[i][l]=idx;
idx--;
ans[i][r]=idx;
idx--;
l--;r++;
}
if(l==)
ans[i][]=idx;
}
for(int i=k;i>=;i--){
for(int j=;j<=cols[i];j++){
if(j==){
printf("%s",people[ans[i][j]].str);
}
else{
printf(" %s",people[ans[i][j]].str);
}
}
printf("\n");
}
return ;
}
05-08 14:50