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 the last row;
All the people in the rear row must be no shorter than anyone standing in the front rows;
In each row, the tallest one stands at the central position (which is defined to be the position (m/2+1), where m is the total number of people in that row, and the division result must be rounded down to the nearest integer);
In each row, other people must enter the row in non-increasing order of their heights, alternately taking their positions first to the right and then to the left of the tallest one (For example, given five people with their heights 190, 188, 186, 175, and 170, the final formation would be 175, 188, 190, 186, and 170. Here we assume that you are facing the group so your left-hand side is the right-hand side of the one at the central position.);
When there are many people having the same height, they must be ordered in alphabetical (increasing) order of their names, and it is guaranteed that there is no duplication of names.
Now given the information of a group of people, you are supposed to write a program to output their formation.
Input Specification:
Each input file contains one test case. For each test case, the first line contains two positive integers N (≤10^4), the total number of people, and K (≤10), the total number of rows. Then N lines follow, each gives the name of a person (no more than 8 English letters without space) and his/her height (an integer in [30, 300]).
Output Specification:
For each case, print the formation -- that is, print the names of people in K lines. The names must be separated by exactly one space, but there must be no extra space at the end of each line. Note: since you are facing the group, people in the rear rows must be printed above the people in the front rows.
Sample Input:
10 3
Tom 188
Mike 170
Eva 168
Tim 160
Joe 190
Ann 168
Bob 175
Nick 186
Amy 160
John 159
Sample Output:
Bob Tom Joe Nick
Ann Mike Eva
Tim Amy John
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
struct student{
string name;
int height;
};
bool cmp(const student& stud1, const student& stud2){
return stud1.height==stud2.height?stud1.name<stud2.name:stud1.height>stud2.height;
}
int main(){
int n, k, cnt=0;
cin>>n>>k;
vector<student> vec(n);
for(int i=0; i<n; i++)
cin>>vec[i].name>>vec[i].height;
sort(vec.begin(), vec.end(), cmp);
for(int i=0; i<k; i++){
int t;
i==0?t=n%k+n/k:t=n/k;
vector<string> q(t);
int mid=t/2;
q[mid]=vec[cnt++].name;
for(int j=1; j<=t/2; j++){
if(mid-j<0)
break;
q[mid-j]=vec[cnt++].name;
if(mid+j>t-1)
break;
q[mid+j]=vec[cnt++].name;
}
for(int j=0; j<t; j++)
j==0?cout<<q[j]:cout<<" "<<q[j];
cout<<endl;
}
return 0;
}
PAT 1109 Group Photo的更多相关文章
- PAT 1109 Group Photo[仿真][难]
1109 Group Photo(25 分) Formation is very important when taking a group photo. Given the rules of for ...
- 1109 Group Photo (25 分)
1109 Group Photo (25 分) Formation is very important when taking a group photo. Given the rules of fo ...
- PAT A1109 Group Photo (25 分)——排序
Formation is very important when taking a group photo. Given the rules of forming K rows with N peop ...
- 1109 Group Photo
Formation is very important when taking a group photo. Given the rules of forming K rows with N peop ...
- 1109. Group Photo (25)
Formation is very important when taking a group photo. Given the rules of forming K rows with N peop ...
- 1109 Group Photo (25分)
Formation is very important when taking a group photo. Given the rules of forming K rows with N peop ...
- PAT (Advanced Level) 1109. Group Photo (25)
简单模拟. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #i ...
- PAT甲题题解-1109. Group Photo (25)-(模拟拍照排队)
题意:n个人,要拍成k行排队,每行 n/k人,多余的都在最后一排. 从第一排到最后一排个子是逐渐增高的,即后一排最低的个子要>=前一排的所有人 每排排列规则如下: 1.中间m/2+1为该排最高: ...
- 【PAT甲级】1109 Group Photo (25分)(模拟)
题意: 输入两个整数N和K(N<=1e4,K<=10),分别表示人数和行数,接着输入N行每行包括学生的姓名(八位无空格字母且唯一)和身高([30,300]的整数).按照身高逆序,姓名字典序 ...
随机推荐
- 【NYOJ42】一笔画问题
一笔画问题 时间限制:3000 ms | 内存限制:65535 KB 难度:4 Position:http://acm.nyist.net/JudgeOnline/problem.php?pid= ...
- bzoj 3993 星际战争
题目大意: X军团和Y军团正在激烈地作战 在战斗的某一阶段,Y军团一共派遣了N个巨型机器人进攻X军团的阵地,其中第i个巨型机器人的装甲值为Ai 当一个巨型机器人的装甲值减少到0或者以下时,这个巨型机 ...
- MSP430:管脚的第二功能选择
之前在使用PWM,AD时候用到过第二功能,不过都是copy没有注意过PXSEL究竟怎么设置,今天在设置晶振管脚时候遇到了麻烦,细致看了一下其实很简单,在SPEC的最后详细讲了每个管脚如何设置为其他功能 ...
- 将本地文件复制到hadoop文件系统
package com.yoyosys.cebbank.bdap.service.mr; import java.io.BufferedInputStream; import java.io.File ...
- 织梦dedecms标签大全总结
织梦dedecms标签大全总结,同时还建议多参考dede默认模板,织梦默认模板上的标签还是很有参考价值的. dedecms系统参数全局标签,在后台系统设置里可以看到这个参数 网站名称:{dede:gl ...
- SS配置,Brook是什么?,Brook如何配置(Android篇)
很长时间没有更新了,今天给大家分享一下什么是Brook,和SS有什么区别?写的不好,请勿见外,大佬绕过. Brook简单介绍 Brook 是一个高效的 Socks5 代理软件,官方支持Windows. ...
- 【洛谷4219】[BJOI2014]大融合(线段树分治)
题目: 洛谷4219 分析: 很明显,查询的是删掉某条边后两端点所在连通块大小的乘积. 有加边和删边,想到LCT.但是我不会用LCT查连通块大小啊.果断弃了 有加边和删边,还跟连通性有关,于是开始yy ...
- WPF PasswordBox MVVM 实现
由于PasswordBox.Password属性非依赖属性,所以不能作为绑定的目标,以下是本人的MVVM实现方法. PasswordBox.Password与TextBox.Text同步,TextBo ...
- Java学习笔记_网络+多线程
支持同时收发的客户端和服务器端 客户端 import javax.swing.*; import java.awt.*; import java.io.*; import java.net.*; im ...
- dotnetnuke 获得List 属性
new DotNetNuke.Common.Lists.ListController().GetListEntryInfo("DataType","Text") ...