Title Link: UVA-11100
Test instructions Description: N suitcase, the same shape, different sizes, small size can be placed in the large size of the suitcase. It is now required to keep the smallest number of suitcases in the outermost suitcase while satisfying the fewest number of suitcases in a suitcase. Find any kind of solution that satisfies the requirement.
Algorithm Analysis: First we can determine the minimum number of travel cases CNT: that is, n travel cases in the size of the size of the category (the same size in the same category), the number of the largest category of the number. CNT is then treated as a CNT heap, and the second requirement is that the maximum number of suitcases in this CNT heap be minimized and processed directly with a vector.
After AC suddenly thought, three suitcase size is 2,2,4, then you can put the first two in the last Ah, but the answer is not so. -_-
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cstdlib>5#include <cmath>6#include <algorithm>7#include <vector>8 #defineINF 0x7fffffff9 using namespacestd;Ten Const intmaxn=10000+Ten; One Const intM =1000000+Ten; A - intN,AN[MAXN]; - intVIS[M],NUM[MAXN]; thevector<int>VEC[MAXN]; - - intMain () - { + intok=0; - while(SCANF ("%d", &n)!=eof &&N) + { A if(OK) printf ("\ n"); atok=1; -memset (Vis,0,sizeof(Vis)); - for(intI=0; i<maxn; i++.) vec[i].clear (); - intCnt=0, maxsize=0; - for(intI=1; i<=n; i++.) - { inscanf"%d",&an[i]); -Vis[an[i]]++; toCnt=Max (Cnt,vis[an[i]]); +Maxsize=Max (maxsize,an[i]); - } theSort (an+1, an+n+1); * intC=0; $ for(intI=1; i<=n; i++.)Panax Notoginseng { - Vec[c].push_back (An[i]); theC= (c+1)%CNT; + } Aprintf"%d\n", CNT); the for(intI=0; i<cnt; i++.) + { - intk=vec[i].size (); $printf"%d", vec[i][0]); $ for(intj=1; j<k; j + +) printf ("%d", Vec[i][j]); -printf"\ n"); - } the } - return 0;Wuyi}
UVA 11100 The trip, 2007 water Problem One