ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

1109 Group Photo

2020-03-25 16:04:32  阅读:30  来源: 互联网

标签:Group name temp int Photo n% height ++ 1109


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

 

标签:Group,name,temp,int,Photo,n%,height,++,1109
来源: https://www.cnblogs.com/keep23456/p/12566751.html

专注分享技术,共同学习,共同进步。侵权联系[admin#icode9.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有