1109 Group Photo

英文题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805360043343872

中文题目:https://pintia.cn/problem-sets/994805260223102976/problems/994805272021680128

 1 #include<iostream>
 2 #include<vector>
 3 #include<algorithm>
 4 using namespace std;
 5 struct node {
 6     string name;
 7     int height;
 8 };
 9 vector<node> v;
10 bool cmp(const node& a,const node& b) {
11     if(a.height != b.height) return a.height > b.height;
12     else return a.name < b.name;
13 }
14 void print(int a,int n) {
15     vector<node> temp(n);
16     temp[n/2] = v[a];
17     int left = n/2 - 1,right = n/2 + 1;
18     for(int i = 1; i < n; ++i) {
19         if(i%2 == 1) temp[left--] = v[a+i];
20         else temp[right++] = v[a+i];
21     }
22     for(int i = 0; i < temp.size(); ++i) {
23         if(i > 0) printf(" ");
24         cout<<temp[i].name;
25     }
26     printf("\n");
27 }
28 int main() {
29     int n,k,height;
30     string name;
31     cin>>n>>k;
32     for(int i = 0; i < n; ++i) {
33         cin>>name>>height;
34         v.push_back({name,height});
35     }
36     sort(v.begin(),v.end(),cmp);
37     int i = 0,m = n/k;
38     if(n%k != 0) print(0,n%k+m),i = n%k+m;
39     while(i < n) {
40         print(i,m);
41         i += m;
42     }
43     return 0;
44 }

 

posted @ 2020-03-25 15:56  tangq123  阅读(135)  评论(0编辑  收藏  举报