题意:给n个数,划分成尽量少的组严格单增序列(可以改变顺序),在此前提下,要求最长序列的len最小
题解:简单贪心,找出现次数最多的数,其出现次数即为组数,然后排序,将所有数均匀分布即可
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#define MAXN 100010
using namespace std;
int a[MAXN];
int n;
int k;
vector<int> v[MAXN];
int main() {
while(scanf("%d",&n)!=EOF && n) {
for(int i = 0;i < n;i++) scanf("%d",&a[i]);
sort(a,a+n);
k = 0;
int cnt = 0;
int num = 0;
for(int i = 0;i < n;i++) {
if(i == 0 || a[i] == a[i-1]) {
cnt++;
if(cnt > k) {
k = cnt;
num = a[i];
}
}
else cnt = 1;
}
printf("%d\n",k);
for(int i = 0;i < MAXN;i++) v[i].clear();
int i = 0;
int pos = 0;
for(;i < n;i++) {
v[pos].push_back(a[i]);
pos = (pos+1) % k;
}
for(i = 0;i < k;i++) {
for(int j = 0;j < v[i].size();j++) {
printf("%d%s",v[i][j],j==(v[i].size()-1)?"\n":" ");
}
}
printf("\n");
}
return 0;
}