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 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 (<=10000), 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
排位置,最高的排在后面,第i排的人的身高必须比第i+1排的人都高,排成k排,每排(int)(n/k)人,多出来的排在第一排,每一排按照最高的在中间,然后按照递减的模式,左边一个右边一个,左边一个。。。一直下去
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n,k;
struct peo
{
char name[];
int height;
}s[];
bool cmp(peo a,peo b)
{
if(a.height == b.height)return strcmp(a.name,b.name) > ;
return a.height < b.height;
}
int main()
{
cin>>n>>k;
for(int i = ;i < n;i ++)
{
cin>>s[i].name>>s[i].height;
}
sort(s,s + n,cmp);
int d = n / k,e = n % k,f = n;
e += d;
while(f)
{
for(int i = e % ? f - e + : f - e;i < f;i += )
{
cout<<s[i].name<<' ';
}
cout<<s[f - ].name;
for(int i = f - ;i >= f - e;i -= )
{
cout<<' '<<s[i].name;
}
cout<<endl;
f -= e;
if(e != d)e = d;
}
}
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 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]的整数).按照身高逆序,姓名字典序 ...
- 1109 Group Photo (25 分)
1109 Group Photo (25 分) Formation is very important when taking a group photo. Given the rules of fo ...
- 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
Formation is very important when taking a group photo. Given the rules of forming K rows with N peop ...
- PAT 1109 Group Photo
Formation is very important when taking a group photo. Given the rules of forming K rows with N peop ...
- PAT_A1109#Group Photo
Source: PAT A1109 Group Photo (25 分) Description: Formation is very important when taking a group ph ...
随机推荐
- [笔记]一道C语言面试题:大整数乘法
题目:输入两个数字字符串,如“1234567890”和“987654321”,返回二者相乘的结果字符串,如本例返回为“1219326311126352690”. 来源:某500强企业面试题目 思路:从 ...
- Hibernate一对多、多对一关联
一对多.多对一关联:在多方加外键 示例:Group(一方)和User(多方),一个Group可以有多个User,每个User只能属于一个Group 多对一单向关联 在User(多方)中建Group ...
- Ubuntu中输入输出重定向及管道技术简述
输出 1.标准输出 定义:程序在默认情况下输出结果的地方(stdout). 2.输出重定向 定义:用于把数据的输出转移到另一个地方去. 3.Ubuntu中例子 $ls > ~/ls_out # ...
- php大转盘抽奖
抽奖大转盘演示:http://www.sucaihuo.com/php/3301.html function getRand($proArr, $proCount) { $result = ''; $ ...
- 前端自动化构建工具-gulp
gulp 和grunt这两个是我知道的自动构建工具,但是说实话都没在项目中用过,不太清楚自动化构建是什么意思, 1.grunt和gulp有什么相同点和不同点? (1).易于使用:采用代码优于配置策略, ...
- BYTE、HANDEL、DWORD等的定义
有时候引入第三方库之后,可能会存在标题的这些变量没有定义,原来这些变量都定义在windows.h里面,包含进去就行了(Qt的MSVC编译器)
- CentOs linux安装SVN服务
SVN服务器有2种运行方式:1.独立服务器(例如:svn://xxx.com/xxx):2.借助apache (例如:http://svn.xxx.com/xxx):为了不依赖apache,我选择 ...
- VisualStudio卸载后无法再次安装的解决方法
解决方法如下: 1.删除 Visual Studio 2013 安装目录文件夹 Visual Studio 12.0 2.win+R 输入 %UserProfile%\Appdata\Local\Mi ...
- PHP(Zend Studio)入门视频
视频地址: http://www.ev-get.com/article/2014/5/9/20962.html (去掉地址中的减号-:可以看视频) Zend Studio教学视频之Zend Studi ...
- 【bzoj1232】[Usaco2008Nov]安慰奶牛cheer(最小生成树)
题目传送门:https://www.lydsy.com/JudgeOnline/problem.php?id=1232 这道题要保留的道路肯定是原图的一棵生成树,因为要保留n-1条边,且使删边后的图连 ...