Problem A: The Trip, 2007
A number of students are members of 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 trip but aren'tquite sure where or when.An issue with the trip is that their very generous sponsors always give them variousknapsacks and other carrying bags that they must pack for their trip home. As the airlineallows only so many pieces of luggage, they decide to pool their gifts and to packone bag within another so as to minimize the total number of pieces they must carry.
The bags are all exactly the same shape and differ only in their linear dimensionwhich is a positive integer not exceeding 1000000. A bag with smaller dimensionwill fit in one with larger dimension. You are to compute which bags to pack withinwhich others so as to minimize the overall number of pieces of luggage(i.e. the number of outermost bags). While maintaining the minimal number ofpieces you are also to minimize the total number of bags in any one piece thatmust be carried.
Standard input contains several test cases. Each test case consists of an integer1 ≤ n ≤ 10000 giving the number of bags followed byn integerson one or more lines,each giving the dimension of a piece. A line containing 0 follows the last testcase. For each test case your output should consist ofk, the minimumnumber of pieces, followed by k lines, each giving the dimensions of thebags comprising one piece, separated by spaces. Each dimension in theinput should appear exactly once in the output, and the bags in each piece mustfit nested one within another. If there is more than one solution, any will do. Outputan 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
Troy Vasiga, Graeme Kemkes, Ian Munro, Gordon V. Cormack
题目大意:给定n个正整数,把他们划分成尽量少的严格递增序列,并且对于每一个划分的数量尽量小,就是使得每个划分尽量平均(这个大白上面没有说)。如:1 1 2 2 2 3 划分成为 {1, 2} {1, 2} {2, 3} 而不是 {1,2,3} {2,3} { 2 }
数字相同的最大的一组数字就是最少的划分组数
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#include <cmath>
#include <string>
#include <queue>
#include <set>
using namespace std;
#ifdef WIN
typedef __int64 LL;
#define iform "%I64d"
#define oform "%I64d\n"
#else
typedef long long LL;
#define iform "%lld"
#define oform "%lld\n"
#endif
const int INF = 0x3f3f3f3f;
const int maxn = 10000 + 20;
int A[maxn];
int main() {
int n;
while(scanf("%d", &n) != EOF && n) {
for(int i=0; i<n; i++) {
scanf("%d", &A[i]);
}
sort(A, A+n);
int k = 0;
int t = 1;
for(int i=0; i<n; i++) {
if(A[i] == A[i-1]) t++;
else {
k = max(k, t);
t = 1;
}
}
k = max(k, t);
printf("%d\n", k);
for(int i=0; i<k; i++) {
int first = 1;
for(int j=i; j<n; j+=k) {
if(!first) printf(" ");
printf("%d", A[j]);
if(first) first = 0;
}
printf("\n");
}
}
return 0;
}