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 }

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

时间: 2024-08-30 13:37:28

1109 Group Photo的相关文章

PAT 1109 Group Photo[仿真][难]

1109 Group Photo(25 分) Formation is very important when taking a group photo. Given the rules of forming K rows with N people as the following: The number of people in each row must be N/K (round down to the nearest integer), with all the extra peopl

1109 Group Photo (25 分)

1109 Group Photo (25 分) Formation is very important when taking a group photo. Given the rules of forming K rows with N people as the following: The number of people in each row must be N/K (round down to the nearest integer), with all the extra peop

PAT 1109 Group Photo

Formation is very important when taking a group photo. Given the rules of forming K rows with N people as the following: The number of people in each row must be N/K (round down to the nearest integer), with all the extra people (if any) standing in

PAT (Advanced Level) 1109. Group Photo (25)

简单模拟. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<queue> #include<stack> #include<string> #include<algorithm> #include<iostream> using namespace std

PAT甲题题解-1109. Group Photo (25)-(模拟拍照排队)

题意:n个人,要拍成k行排队,每行 n/k人,多余的都在最后一排. 从第一排到最后一排个子是逐渐增高的,即后一排最低的个子要>=前一排的所有人 每排排列规则如下: 1.中间m/2+1为该排最高: 2.其他人按各自降序顺序,轮流排到中间最高的左边和右边: 举个例子 190 188 186 175 170 - - 190 - - - 188 190 - - - 188 190 186 - 175 188 190 186 - 175 188 190 186 170 3.当个子一样高时,名字按字典序顺序

【PAT甲级】1109 Group Photo (25分)(模拟)

题意: 输入两个整数N和K(N<=1e4,K<=10),分别表示人数和行数,接着输入N行每行包括学生的姓名(八位无空格字母且唯一)和身高([30,300]的整数).按照身高逆序,姓名字典序升序将学生从高到矮排列,将学生均分为N行输出,最先输出的一行人数包括除不尽的余数学生,每行中间(如果这一行学生人数为偶数则靠右的为中间)的学生最高,然后依次左边一位学生最高,右边一位学生最高,例如190, 188, 186, 175, 170->175, 188, 190, 186, 170. tric

A题目

1 1001 A+B Format(20) 2 1002 A+B for Polynomials(25) 3 1003 Emergency(25) 4 1004 Counting Leaves(30) 5 1005 Spell It Right(20) 6 1006 Sign In and Sign Out(25) 7 1007 Maximum Subsequence Sum(25) 8 1008 Elevator(20) 9 1009 Product of Polynomials(25) 10

Codeforces VK Cup 2015 Wild Card Round 1 (AB)

比赛链接:http://codeforces.com/contest/522 A. Reposts time limit per test:1 second memory limit per test:256 megabytes One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started

[翻译]小提示:使用figure和figcaption元素的正确方式

figure和figcaption是一对经常被一起使用的语义化标签.如果你还没有看过规范中的定义,现在有机会在你的项目中使用它们了.如果你不知道怎么用,下面是关于如何正确使用它们的一些提示. figure元素经常用于image: <figure> <img src="dog.jpg" alt="Maltese Terrier"> </figure> figure元素表示内容的自包含单元.这个含义是,如果你把元素无论是移出文档或移动