UVA 11100 the Trip, 2007

Source: Internet
Author: User
Tags pack

Original question:
A number of students is members of a club, travels annually to exotic locations.
Their destinations in the past has included Indianapolis, Phoenix,
Nashville, Philadelphia, San Jose, Atlanta, Eindhoven, Orlando, Vancouver,honolulu, Beverly Hills, Prague, Shanghai, and S An Antonio. This spring they is hoping to make a similar trips but
Aren ' t quite sure where or when. An issue with the trip are that their very generous sponsors all give them various knapsacks and other carrying bags tha T they must pack for their trip home.
As the airline allows only so many pieces of luggage, they decide to pool their gifts and to pack one bag within another s O As to minimize the total number of pieces they must carry.
The bags-exactly the same shape and differ only in their linear dimension which is a positive
Integer not exceeding 1000000. A bag with smaller dimension would fit in one with larger dimension. You is to compute which bags to pack within which others so as to minimize the overall number of pieces of (luggage). The number of outermost bags). While maintaining the minimal number of pieces you is also to minimize the total number of bags in any one piece that Mus t be carried.
Input
Standard input contains several test cases. Each test case consists of an integer 1≤n≤10000 giving
The number of bags followed by n integers in one or more lines, each giving the dimension of a piece.
A line containing 0 follows the last test case.
Output
For all test case your output should consist of K, the minimum number of pieces, followed by K lines,
Each giving the dimensions of the bags comprising one piece, separated by spaces. Each dimension in
The input should appear exactly once in the output, and the bags in each piece must fit nested one
Within another. If there is more than one solution, any would do. Output an empty line between cases.
Sample Input
6
1 1 2 2 2 3
0
Sample Output
3
1 2
1 2
3 2
Effect:
Give you the number, now let you divide into as few as possible strict increment sequence. First, the minimum value of the sequence number is output, and then the sequence is counted.

#include <bits/stdc++.h> using namespace std;
int a[1000001],b[10001];
Vector<int> VI;
    int main () {Ios::sync_with_stdio (false);
    int n,ans,tmp;
        while (cin>>n,n) {memset (a,0,sizeof (a));
        Memset (b,0,sizeof (b));
        Vi.clear ();
        Ans=1;
        cin>>b[1];
        TMP=B[1];
        a[b[1]]++;
            for (int i=2;i<=n;i++) {cin>>b[i];
            a[b[i]]++;
        if (A[b[i]]>ans) ans=a[b[i]];
        } cout<<ans<<endl;
        Sort (b+1,b+1+n);
            for (int i=1;i<=ans;i++) {vi.clear ();
            for (int J=i;j<=n;j=j+ans) Vi.push_back (B[j]); for (int k=0;k<vi.size (); k++) {if (K!=vi.size ()-1) cout<<vi[k]<
                < "";
            else cout<<vi[k]<<endl;
}}} return 0;
 }

Answer:
This topic let the first solution of the output is very good to think, but the output scheme to think more, later looked at someone else's code, instantly understand.
Minimum number of groups, but also to keep the output of the sequence is strictly incremented, then the minimum number must be the number of occurrences of the most number in the array, the answer is ans. Then each time you select the number of ans for the span, then output the scheme.

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.