Uva--11100the Trip, 2007

Source: Internet
Author: User

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

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.