# 1055 集体照

10 3
Tom 188
Mike 170
Eva 168
Tim 160
Joe 190
Ann 168
Bob 175
Nick 186
Amy 160
John 159


Bob Tom Joe Nick
Ann Mike Eva
Tim Amy John


#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;
typedef pair<string,int> PII;
int n,k;
PII a[10010];
vector<vector<PII>> res;

bool cmp(PII m,PII n)
{
if(m.second!=n.second)
return m.second>n.second;
else
return m.first<n.first;
}
int main()
{
cin >> n>> k;
int num=n/k;
int remain=n-(k-1)*num;
for(int i=0;i<n;i++)
cin >> a[i].first >> a[i].second;
sort(a,a+n,cmp);
int t=0,cnt=k;
while(cnt)
{
int sum;
if(cnt==k)
sum=remain;
else
sum=num;
vector<PII> zancun(sum);
int j=sum/2-1;
for(int k=t+1;k<t+sum;k+=2)
{
zancun[j].first=a[k].first;
zancun[j].second=a[k].second;
j--;
}
j=sum/2;
for(int k=t;k<t+sum;k+=2)
{
zancun[j].first=a[k].first;
zancun[j].second=a[k].second;
j++;
}
res.push_back(zancun);
t+=sum;
cnt--;
}
for(int i=0;i<res.size();i++)
{
for(int q=0;q<res[i].size();q++)
{
if(q!=0)
printf(" ");
cout << res[i][q].first;
}
printf("\n");
}
return 0;
}



©️2019 CSDN 皮肤主题: 1024 设计师: 上身试试