-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathA1109.cpp
75 lines (72 loc) · 1.43 KB
/
A1109.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include<vector>
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
struct record
{
string name;
int h;
};
bool operator<(const record & r1, const record & r2)
{
if(r1.h!=r2.h)
{
return r1.h<r2.h;
} else return r1.name>r2.name;
}
void fun( vector<record> & v){
if(v.size()==1)return;
int m = v.size();
int center = m/2;
vector<record> tmp(v.size() );
int i = m-2;
int step = -1;
tmp[center] = v[m-1];
while(1){
tmp[center+step] = v[i--];
if(i==-1)break;
step*=-1;
tmp[center+step] = v[i--];
if(i==-1)break;
step*=-1;
step--;
}
v=tmp;
}
void print(const vector<record> & v)
{
for(int i = 0; i < v.size(); i++){
if(i>0) cout << " ";
cout << v[i].name;
}
cout << endl;
}
int main()
{
int n,m;
cin >> n >> m;
vector<record> v;
for(int i = 0; i < n; i++){
record tmp;
cin >> tmp.name>> tmp.h;
v.push_back(tmp);
}
int num = n/m;
sort(v.begin(),v.end());
vector<vector<record>> ans(m);
for(int i = 0; i < m; i++){
if(i!=m-1){
for(int j = num*i; j < num*(i+1); j++) {
ans[i].push_back(v[j]);
}
} else
for(int j = num*i; j < n; j++ ){
ans[i].push_back(v[j]);
}
}
for(int i = m-1; i >=0; i--){
fun(ans[i]);
print(ans[i]);
}
}