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 (≤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

分析:一开始想的是把左右两边都排序一次,但感觉较复杂且肯定耗时大,后来还是参考了柳神的代码。。思路清晰。。

具体做法:每排一个大循环,最大的先插入,两侧的按序一个个插入,插入过程中i=i+2,注意跳出条件。

 #include<cstdio>
 #include<cstring>
 #include<iostream>
 #include<cmath>
 #include<algorithm>
 #include<vector>
 using namespace std;
 struct student{
     string name;
     int h;
 };

 bool cmp(student a,student b){
     if(a.h!=b.h) return a.h>b.h;
     else if(a.name!=b.name) return a.name<b.name;
 }

 int main()
 {
 #ifdef ONLINE_JUDGE
 #else
     freopen("1.txt", "r", stdin);
 #endif
     int n,k,i,j,m;
     cin>>n>>k;
     vector<student> stu(n);
     ;i<n;i++){
         cin>>stu[i].name>>stu[i].h;
     }
     sort(stu.begin(),stu.end(),cmp);
     ,row=k;
     while(row){
         if(row==k){
             m=n/k+n%k;
         }
         else m=n/k;
         vector<string> ans(m);
         ans[m/]=stu[t].name;
         j=m/-;
         ;i<t+m;i=i+){
             ans[j--]=stu[i].name;
         }
         j=m/+;
         ;i<t+m;i=i+){
             ans[j++]=stu[i].name;
         }
         cout<<ans[];
         ;i<m;i++){
             cout<<" "<<ans[i];
         }
         cout<<endl;
         t=t+m;
         row--;
     }
     ;
 }

1109 Group Photo (25 分)的更多相关文章

  1. 1109 Group Photo (25分)

    Formation is very important when taking a group photo. Given the rules of forming K rows with N peop ...

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

    题意: 输入两个整数N和K(N<=1e4,K<=10),分别表示人数和行数,接着输入N行每行包括学生的姓名(八位无空格字母且唯一)和身高([30,300]的整数).按照身高逆序,姓名字典序 ...

  3. 1109. Group Photo (25)

    Formation is very important when taking a group photo. Given the rules of forming K rows with N peop ...

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

    简单模拟. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #i ...

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

    题意:n个人,要拍成k行排队,每行 n/k人,多余的都在最后一排. 从第一排到最后一排个子是逐渐增高的,即后一排最低的个子要>=前一排的所有人 每排排列规则如下: 1.中间m/2+1为该排最高: ...

  6. PAT 1109 Group Photo[仿真][难]

    1109 Group Photo(25 分) Formation is very important when taking a group photo. Given the rules of for ...

  7. 1109 Group Photo

    Formation is very important when taking a group photo. Given the rules of forming K rows with N peop ...

  8. PAT 1109 Group Photo

    Formation is very important when taking a group photo. Given the rules of forming K rows with N peop ...

  9. PAT_A1109#Group Photo

    Source: PAT A1109 Group Photo (25 分) Description: Formation is very important when taking a group ph ...

随机推荐

  1. 太完美 TWM000极度精简版XP20130123终结美化版

    TWM000极度精简版XP20130123终结美化版:蛋蛋20130123终结版为蓝本,虫子提供的美化包进行了美化.此版经测试完美在Z77主板开启AHCI安装,此为最终版之美化版!LiteXPMH.i ...

  2. Ubuntu:火狐浏览器加速下载(Flashgot+Aria2+Uget)

    火狐浏览器加速下载 应用到的程序 Aria2 Uget firefox插件Flashgot 1.下载Uget sudo apt-get install uget 2. 下载Aria2 sudo apt ...

  3. ios之开发屏幕适配和系统版本适配

    ios软件开发过程中很重要的一点是对系统和屏幕进行适配对系统的适配主要是IOS7以后和之前以及IOS8新增特性,屏幕适配主要是对不同设备采用不同的布局以最佳展示效果展现给用户. 针对系统的适配: IO ...

  4. MAC中安卓开发环境的下载

    今天终于为我的Macbook Pro Retina搭建好了Android开发环境,几经折磨,差点放弃了: 总结如下:1.最好选择ADT Bundle,这里面已经集成好了Eclipse.ADT.Andr ...

  5. C高级第一次PTA作业 要求三

    要求一.要求二 内容链接:http://www.cnblogs.com/X-JY/p/8550457.html 一.PTA作业中的知识点总结 1.6-1 计算两数的和与差(10 分) (1)*在程序中 ...

  6. DS博客作业04--树大作业说明

    大作业题目说明 1.目录树 按照如下目录路径,设计一颗目录树保存.并能实现对目录树遍历.目录路径存在file.txt,格式如下: b.txt c\ ab\cd.txt a\bc.txt ab\d.tx ...

  7. Tomcat问题:Neither the JAVA_HOME nor the JRE_HOME environment variable is defined ,At least one of these environment variable is needed to run this program

    一眼就能看出来是jdk的环境有问题,但是用了这么久的jdk一直都配置的好好的,怎么一到Tomcat上就这么矫情了. 最后查解决方案,原来是我的jdk从官网直接下载的,虽然我修改了java_home,但 ...

  8. [HRBUST-1688]数论中的异或(思维题)

    数论中的异或 Time Limit: 1000 MS Memory Limit: 32768 K Total Submit: 75(41 users) Total Accepted: 35(30 us ...

  9. python--selenium实用的自动生成测试HTML报告方法--HTMLTestRunner

    python--selenium实用的自动生成测试HTML报告方法--HTMLTestRunner 下面给大家介绍下用HTMLTestRunner模块自动生成测试报告的方法. 一.首先我们导入unit ...

  10. JS校验 if (! temp_var) {} //拦截 ''和 undefined

    if (! aaa) {}  //拦截   ' '  和  undefined  和  0 不拦截null