Test instructions
Now there are n different capacity packages, their capacity is represented by numbers; The small package can be nested into a large package (but only one package per package), so that the minimum number of packages to be mentioned in the final package, while keeping the minimum number of packages, It is also necessary to make the maximum number of packets packed in each large bag as small as possible.
Ideas:
At first it was not clear what the minimum number of packets should be, and then suddenly it was discovered that the minimum number of packets that could be retained at the end of the pack would be the most numerous (as CNT). To figure this out, we need to consider the problem of the number of packets that are required in the title as little as possible, in order to achieve this goal we can make the packet in each package as far as possible to balance the number of packets, we can choose the former CNT as the last packet of the package, and then to the inside of the bag, so that we can achieve Also pay attention to the format problem, the topic requires a space between each number, but the last number can not be output space after.
The code is as follows:
<span style= "FONT-SIZE:18PX;" > #include <iostream> #include <cstdio> #include <cstring> #include <algorithm>using Namespace Std;int a[11000],b[1100000];int Main () { int i,j,k,n,case=0; while (scanf ("%d", &n) &&n) { memset (b,0,sizeof (b)); int cnt=0; for (i=0;i<n;i++) { scanf ("%d", &a[i]); b[a[i]]++; Cnt=max (Cnt,b[a[i]); } Sort (a,a+n); printf ("%d\n", CNT); for (i=0;i<cnt;i++) { j=i+cnt; printf ("%d", A[i]); while (J<n) { printf ("%d", a[j]); j+=cnt; } printf ("\ n"); } printf ("\ n"); } return 0;} </span>
Uva--11100the Trip, 2007