1055. Group photo (25)

Source: Internet
Author: User

The formation of the group is very important, here for a given n individual K row formation design queue rules are as follows:

    • The number of n/k per row (rounded down), the number of people all stand in the last row;
    • Everyone in the back row is not shorter than anyone in the front row;
    • The middle of the highest station in each row (the middle position is m/2+1, where M is the number of the platoon, Division is rounded down);
    • Each platoon other people with the middleman as the axis, according to the height of non-sequential, first right after the left alternately to stand on the side of the middle man (for example, 5 people height of 190, 188, 186, 175, 170, the formation of 175, 188, 190, 186, 170. This assumes that you are facing the photographer, so your left side is the middleman's right side);
    • If more than one person is the same height, the dictionary order is sorted in ascending order by name. No duplicate names are guaranteed here.

Now given a group of photographers, write programs to output their formations.

Input Format:

Each input consists of 1 test cases. The 1th line of each test case gives two positive integers n (<=10000, total number) and K (<=10, total rows). Then n rows, each row gives a person's name (no spaces, no more than 8 letters in length) and height (integers in the [30, 300] interval).

output Format:

Output the formation of a photograph. That is, the name of the K row, between the space separated by the end of the line must not have extra space. Note: Suppose you face the photographer, the back of the person output is above, the front row output is below.

Input Sample:

3Tom 188Mike 170Eva 168Tim 160Joe 190Ann 168Bob 175Nick 186Amy 160John 159
Sample output:
Bob Tom Joe Nickann Mike evatim Amy John
//1055#include <iostream>#include<vector>#include<string>#include<algorithm>using namespacestd;structperson{stringname; intheight;};BOOLCMP (person & A, person&b) {    if(A.height! =b.height) {returnA.height>B.height; }    Else {        returna.name<B.name; }}intMain () {intn,k; CIN>> N >>K; intm = N/K; Vector<person>PEO (N); Vector<vector<person>> BK (K-1,vector<person>(m));  for(inti =0; i < N; i++) {cin>> Peo[i].name >>Peo[i].height;    } sort (Peo.begin (), Peo.end (), CMP); intFST = N% K +m; Vector<person>BK1 (FST); inti =0; intCNT =0; //processing the first line    intIDX1 = FST/2;  for(; i < FST; + +)i) {bk1[idx1]=Peo[i]; ++CNT; ifI2==0&& (idx1>=0&&idx1<FST)) {idx1-=CNT; }        Else if(idx1>=0&&idx1<FST) {idx1+=CNT; }} CNT=0; //working with multiple remaining rows    intIDX2 = m/2;  for(intt =0; T < K1; ++t) { for(intj =0; J < M; J + +) {BK[T][IDX2]= peo[i++]; ++CNT; if(J%2==0&& (idx2 >=0&& idx2<FST)) {IDX2-=CNT; }            Else if(Idx2 >=0&& idx2<FST) {IDX2+=CNT; }} CNT=0; IDX2= m/2; }        //Output     for(i =0; i < FST; i++)    {        if(i = =0) cout <<Bk1[i].name; Elsecout <<" "<<Bk1[i].name; } cout<<Endl;  for(i =0; I < K1; i++)    {         for(intj =0; J < M; J + +)        {            if(J = =0) cout <<Bk[i][j].name; Elsecout <<" "<<Bk[i][j].name; } cout<<Endl; }    return 0;}

1055. Group photo (25)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.