UVa 11100:the Trip, 2007

Source: Internet
Author: User
Tags bool pack printf sort

Link

Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=113&page=show_ problem&problem=2041

"Original question"

A number of students are members of the A club that travels annually to exotic locations. Their destinations in the past have included Indianapolis, Phoenix, Nashville, Philadelphia, San Jose, Atlanta, Eindhoven, Orlando, Vancouver, Honolulu, Beverly Hills, Prague, Shanghai, and San Antonio. This spring they are hoping to make a similar trips but aren ' t quite sure where or when.

A issue with the "trip is" their very generous sponsors always 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 are all exactly the same shape and differ to in their linear-dimension-A which integer not positive G 1000000. A bag with smaller dimension would fit into one with larger dimension. You are are to compute which bags to pack within which others-as to minimize the overall number of pieces of luggage (i.e. The number of outermost bags). While maintaining the minimal number of pieces for you are also to minimize the total number of bags into any one one piece that Mus t be carried.

This column more highlights: http://www.bianceng.cn/Programming/sjjg/

Standard input contains several test cases. Each test case consists of 1≤n≤10000 giving the number of bags followed through n integers on one or more lines, Each giving the dimension of a piece. A line containing 0 follows of the last Test case. For each test case your output should consist of K, the minimum number of pieces, followed by k lines, each giving the dim Ensions of the bags comprising one piece, separated by spaces. Each dimension in the input should appear exactly once in the output, and the bags at each piece must fit nested one Withi N another. If there is more than one solution, the any would do. Output an empty line between cases.

Sample Input

6
1 1 2 2 2 3
0

Output for Sample Input

3
1 2
1 2 3 2

"The main effect of the topic"

Gives n numbers, representing the size of n packets. A small bag can be packed into a larger bag and can be nested all the way down. Let these packages be packaged up and made into a minimum package.

"Analysis and Summary"

Say my first thought.

It's easy to think of a sort, and then there will be the same number, like 1,2,2,3,3,3,4,4,4,4, in order to get as much packaging into the bag as possible, then choose an incremental sequence with no repeat numbers, such as 1,2,3,4, that meets the requirements. So is 2,3,4. The maximum number of repetitions is the last number of packets left.

But this was submitted by WA. The idea is correct, that is, the output is wrong, this does not know why, personally feel that this output should also be able to, the topic has said that there are a variety of options, any one can be ...

At last, we look at the output method on the net, each time with the number of repeated digits as the difference from the output scheme.

Code

* * Uva:11100-the Trip, 2007 * time:0.112s * * * * * * * * * * * * * * #include <iostream> #include &  
lt;cstdio> #include <cstring> #include <algorithm> #define MAXN 20000 using namespace std;  
int ARR[MAXN], n, ANS[MAXN];  
      
BOOL VIS[MAXN];  
    void Solve () {sort (arr, arr+n);  
    int max=1;  
    int i=1;  
        while (i<n) {int cnt=1;  
        while (arr[i]==arr[i-1]&&i<n) {++cnt; ++i}  
        if (Cnt>max) max=cnt;  
    ++i;  
    printf ("%d\n", Max);  
    memset (Vis, 0, sizeof (VIS));  
      
    i=0;  
        while (1) {for (i=0; i<n; ++i) if (!vis[i)) a break;  
        printf ("%d", arr[i]);  
        Vis[i] = true;  
        i = Max;  
                while (i<n) {if (!vis[i]) {printf ("%d", arr[i]);  
            Vis[i] = true;  
        i = = Max;  
        printf ("\ n");  
        BOOL Flag=false; for (int i=0; I&LT;n;  
        ++i) if (!vis[i]) {flag=true;  
    } if (!flag) break;  
    int main () {bool flag=false;  
        while (scanf ("%d", &n) &&n) {for (int i=0; i<n; ++i) scanf ("%d", &arr[i]);  
        if (flag) printf ("\ n");  
        else flag=true;   
    Solve ();  
return 0; }

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.