// 部分正確!
//
#include "stdafx.h"
#include<iostream>
#include<string>
#include<utility>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
unsigned n, k;
cin >> n >> k;
//讀取輸入數(shù)據(jù)
string tmp_name;
unsigned tmp_high;
vector<pair<string, unsigned>> data;
for (unsigned i = 0; i < n; ++i)
{
cin >> tmp_name >> tmp_high;
data.push_back(make_pair(tmp_name, tmp_high));
}
//根據(jù)身高和姓氏排序
//sort(data.begin(), data.end(), [](pair<string, unsigned> lh, pair<string, unsigned> rh) {return lh.first < rh.first; });
stable_sort(data.begin(), data.end(), [](pair<string, unsigned> lh, pair<string, unsigned> rh) {return lh.second < rh.second; });
//對(duì)輸入的數(shù)據(jù)進(jìn)行切片
vector<vector<pair<string, unsigned>>> format_data;
unsigned m = floor(n*1.0 / k*1.0);
unsigned last_m = n - m*(k - 1);
auto beg = data.begin();
for (size_t i = 0; i < k;++i)
{
if (i != (k - 1))
{
vector<pair<string, unsigned>> tmp(beg, beg + m);
sort(tmp.begin(), tmp.end(), [](pair<string, unsigned> lh, pair<string, unsigned> rh) {return lh.first < rh.first; });
stable_sort(tmp.begin(), tmp.end(), [](pair<string, unsigned> lh, pair<string, unsigned> rh) {return lh.second > rh.second; });
format_data.push_back(tmp);
beg = beg + m;
}
else
{
vector<pair<string, unsigned>> tmp(beg, data.end());
sort(tmp.begin(), tmp.end(), [](pair<string, unsigned> lh, pair<string, unsigned> rh) {return lh.first < rh.first; });
stable_sort(tmp.begin(), tmp.end(), [](pair<string, unsigned> lh, pair<string, unsigned> rh) {return lh.second > rh.second; });
format_data.push_back(tmp);
beg = beg + m;
}
}
//根據(jù)規(guī)則排序
vector<vector<string>> out_format(k-1, vector<string>(m," "));
out_format.push_back(vector<string>(last_m,""));
unsigned now_middle;
int change_r_l = 0;
int r_l = 0;
for (size_t i = 0; i < format_data.size(); ++i)
{
now_middle = format_data[i].size()/2+1;
for (size_t j = 0; j < format_data[i].size(); ++j)
{
out_format[i][now_middle - 1] = format_data[i][j].first;
now_middle = now_middle- pow(-1, j)*(j + 1);
}
}
for (int i=out_format.size()-1;i>=0;--i)
{
for (size_t j = 0; j < out_format[i].size(); ++j)
{
cout << out_format[i][j];
if (j != (out_format[i].size() - 1))
cout << " ";
}
if(i!=0)
cout << endl;
}
system("pause");
return 0;
}
1055
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
相關(guān)閱讀更多精彩內(nèi)容
- 比利時(shí)攝影師Wim Denijs的這些風(fēng)光作品雖然不能用壯麗華美來(lái)形容,但在平靜的同時(shí),也有著相當(dāng)不錯(cuò)的氛圍和情感...
- 那是二零零二年秋收后,在那年的第一場(chǎng)雪還沒(méi)有來(lái)的時(shí)候,我坐著的長(zhǎng)途大巴車,把我扔在了廣深高速公路長(zhǎng)安出口的天橋上。...
- 這一年,似乎既漫長(zhǎng)又短暫。 因?yàn)閴?mèng)想,在這一年里不斷沉淀。 凌晨有多少人進(jìn)入夢(mèng)鄉(xiāng), 時(shí)光在一次又一次的考試中漸漸褪...