版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Nightmare_ak/article/details/84791624
模拟,高的且字典序小的排前面,一排排模拟下去即可。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
using namespace std;
const int N=1e4+5;
struct People
{
char name[12];
int height;
bool operator<(const People&p)const
{
if(height!=p.height) return height>p.height;
return strcmp(name,p.name)<0;
}
}p[N];
string mp[15][N];
int main()
{
int n,k;
scanf("%d%d",&n,&k);
for(int i=1;i<=n;i++)
scanf("%s%d",p[i].name,&p[i].height);
sort(p+1,p+n+1);
int sum=0;
for(int i=1;i<=k;i++)
{
int num=n/k;
if(i==1) num+=n-num*k;
int pre=num/2+1;
for(int j=1;j<=num;j++)
{
mp[i][pre]=p[sum+j].name;
if(j&1) pre-=j;
else pre+=j;
}
sum+=num;
}
for(int i=1;i<=k;i++)
{
int num=n/k;
if(i==1) num+=n-num*k;
for(int j=1;j<=num;j++)
printf("%s%c",mp[i][j].c_str()," \n"[j==num]);
}
return 0;
}