Pat a problem-1109. Group photo (25)-(analog photo queue)

Source: Internet
Author: User

Test instructions: N people, to make a line of k lines, each line n/k people, the surplus is in the last row.

From the first row to the last row, the stature is gradually increasing, that is, the lowest of the next row is >= everyone in the previous row.

The following rules are arranged for each row:

1. The middle m/2+1 is the highest in the row;

2. Others, in descending order, rotate to the top left and right of the middle;

For example 190 188 186 175 170

--190--

-188 190--

-188 190 186-

175 188 190 186-

175 188 190) 186 170

3. When the height is the same, the name is in the order of the dictionary, before the first line into the team.

Pure simulation, nothing to say.

#include <iostream>#include<cstdio>#include<string.h>#include<algorithm>using namespacestd;Const intmaxn=10000+5;structpeople{Charstr[ -]; intheight; BOOL operator< (ConstPeople tmp)Const{        if(height==tmp.height) {            if(strcmp (STR,TMP.STR) <0)                return false; Else                return true; }        Else{            returnheight<Tmp.height; }}}PEOPLE[MAXN];intMain () {intK,n; scanf ("%d%d",&n,&k); intans[k+1][MAXN]; intcols[k+1];  for(intI=0; i<n;i++) {scanf ("%s%d",people[i].str,&people[i].height); } sort (People,people+N); intm=n/K; intLeft,right;  for(intI=1; i<=k;i++) { left= (I-1)*m; Right=i*m-1; if(i==k) {m=n-(K-1)*m; Right=n-1; } Cols[i]=m; intcenter=m/2+1; intidx=Right ; Ans[i][center]=idx; IDX--; intl=center-1, r=center+1;  while(r<=m) {Ans[i][l]=idx; IDX--; ANS[I][R]=idx; IDX--; L--;r++; }        if(l==1) ans[i][1]=idx; }     for(inti=k;i>=1; i--){         for(intj=1; j<=cols[i];j++){            if(j== on) {printf ("%s", PEOPLE[ANS[I][J]].STR); }            Else{printf ("%s", PEOPLE[ANS[I][J]].STR); }} printf ("\ n"); }    return 0;}
View Code

Pat a problem-1109. Group photo (25)-(analog photo queue)

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.