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)