码迷,mamicode.com
首页 > 其他好文 > 详细

1109 Group Photo

时间:2020-03-25 16:13:14      阅读:60      评论:0      收藏:0      [点我收藏+]

标签:info   node   ack   else   style   ++   图片   oid   ems   

英文题目: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 }

技术图片

 

1109 Group Photo

标签:info   node   ack   else   style   ++   图片   oid   ems   

原文地址:https://www.cnblogs.com/keep23456/p/12566751.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!