The trip (Uva 11100)

Source: Internet
Author: User

Main topic:

The number of n is given, it is required to be divided into the least increment sequence, so that the minimum sequence length is minimized. n<=10000

Exercises

1. I looked directly at the Chinese side of the training guide, and Lrj seemed to forget to mention "the minimum number of sequence lengths to ensure that the sequence is minimal" and WA to die. My approach is to count the number of occurrences of each number, and then construct the longest sequence whenever possible, so that the number of sequences is minimal, but the second condition is clearly not satisfied.

2. Because before WA to die, it is very lack of ambition Baidu has the puzzle. Then a glance at the fewest number of sequences is the number of occurrences (recorded in m) of the most frequently occurring numbers. And then all of a sudden you do it. First, all the numbers are sorted from small to large, and then the NO. 0 number is assigned to the NO. 0 sequence, and the 1th number is the sequence of 1th .... The number of I is assigned to the sequence of the first (I mod m). This clearly conforms to the test instructions, and the length of each sequence is very average, and the maximum value of the sequence length must be minimal.

Code:

1#include <iostream>2#include <cstdio>3#include <cmath>4#include <cstring>5#include <algorithm>6#include <vector>7#include <map>8#include <cstdlib>9#include <Set>Ten using namespacestd; One  A #defineX First - #defineY Second - #defineN 10010 thetypedefLong Longll; -typedef pair<int,int>PII; -  - intN,m,tot; + intV[n],b[n],cnt[n]; -vector<int>G[n]; +  A intMain () at { -     //freopen ("in.in", "R", stdin); -     //freopen ("Out.out", "w", stdout); -      -      while(SCANF ("%d",&N)) -     { in         if(n==0) Break; -          for(intI=0; i<n;i++) scanf ("%d",&v[i]); toSort (v,v+n); tot=m=0; +      -          for(intI=0; i<n;i++) the         { *             if(i==0|| v[i]!=v[i-1]) cnt[tot++]=1; $             Elsecnt[tot-1]++;Panax Notoginseng         }  -          for(intI=0; i<tot;i++)if(Cnt[i]>cnt[m]) m=i; them=Cnt[m]; +printf"%d\n", m); A          for(intI=0; i<m;i++) g[i].clear (); the          for(intI=0; i<n;i++) g[i%M].push_back (V[i]); +          -          for(intI=0; i<m;i++) $         { $              for(intj=0; J<g[i].size (); j + +) -             { -printf"%d", G[i][j]); theprintf"%c", J==g[i].size ()-1?'\ n':' '); -             }Wuyi         } the     } -      Wu     return 0; -}

The trip (Uva 11100)

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.