Skip to content

Commit e08c97b

Browse files
committedFeb 28, 2019
AC
1 parent 754e911 commit e08c97b

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#include <iostream>
2+
#include <string>
3+
#include <algorithm>
4+
#include <vector>
5+
using namespace std;
6+
7+
struct Node{
8+
string name;
9+
int height;
10+
11+
bool operator < (Node & b){
12+
if(height != b.height)
13+
return height > b.height;
14+
else
15+
return name < b.name;
16+
}
17+
};
18+
int main(){
19+
int N, K, M;
20+
Node arr[10005];
21+
scanf("%d %d", &N, &K);
22+
// central = m / 2 + 1
23+
for(int i = 0; i < N; ++i)
24+
cin >> arr[i].name >> arr[i].height;
25+
26+
sort(arr, arr+N);
27+
28+
int curRow = K;
29+
int idx = 0;
30+
while(curRow){
31+
if(curRow == K)
32+
M = N - N/K*(K-1);
33+
else M = N/K;
34+
vector<string> ans(M);
35+
36+
int mid = M/2;
37+
ans[mid] = arr[idx].name;
38+
int j = mid - 1;
39+
for(int i = idx+1; i < idx + M; i += 2)
40+
ans[j--] = arr[i].name;
41+
j = mid + 1;
42+
for(int i = idx+2; i < idx + M; i += 2)
43+
ans[j++] = arr[i].name;
44+
45+
cout << ans[0];
46+
for(int i = 1; i < M; ++i)
47+
cout << " " << ans[i];
48+
cout << endl;
49+
curRow--;
50+
idx += M;
51+
}
52+
return 0;
53+
}

0 commit comments

Comments
 (0)
Please sign in to comment.