# 代码

#include <bits/stdc++.h>
using namespace std;

#define rep(i, s, t) for (int i = (int)(s); i <= (int)(t); ++ i)

const int maxn = 1e4 + 10;
int a[maxn], n;

vector<int> b[maxn];

bool check(int m) {
for (int i = 0; i < maxn; ++ i) b[i].clear();
for (int i = 1; i <= m; ++ i) b[i].push_back(a[i]);
for (int i = m + 1; i <= n; ++ i) {
int next = (i - 1) % m + 1;
if (a[i] < *(b[next].end() - 1)) b[next].push_back(a[i]);
else return false;
}
return true;
}

int main() {
while (~scanf("%d", &n) && n) {
rep(i, 1, n) scanf("%d", a + i);
sort(a + 1, a + n + 1); reverse(a + 1, a + n + 1);
int l = 1, r = n, mid;
while (l < r) {
if (check(mid = (l + r) >> 1)) r = mid; else l = mid + 1;
}
check(l); printf("%d\n", l);
vector<int>::iterator it;
for (int i = 1; i <= l; ++ i) {
sort(b[i].begin(), b[i].end());
printf("%d", *b[i].begin());
for (it = b[i].begin()+1; it != b[i].end(); ++ it) {
printf(" %d", *it);
}
putchar(10);
}
putchar(10);
}
}

posted @ 2018-11-24 11:55  AlessandroChen  阅读(199)  评论(0编辑  收藏  举报