UVA - 11100 - The Trip, 2007(简单思路)

题意:给定n(1 <= n <= 10000)个正整数,把它们划分成尽量少的严格递增序列,如果有多解,尽量让这些序列中最大长度最小。

序列的个数最少肯定为,出现最多的数字的次数,然后不断向其中填数即可。

 

#include<cstdio>
#include<cstring>
#include<cctype>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<list>
#define fin freopen("in.txt", "r", stdin)
#define fout freopen("out.txt", "w", stdout)
#define pr(x) cout << #x << " : " << x << "   "
#define prln(x) cout << #x << " : " << x << endl
typedef long long ll;
typedef unsigned long long llu;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const ll LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const double pi = acos(-1.0);
const double EPS = 1e-6;
const int dx[] = {0, 0, -1, 1};
const int dy[] = {-1, 1, 0, 0};
const ll MOD = 1e9 + 7;
const int MAXN = 10000 + 10;
const int MAXT = 1000000 + 10;
using namespace std;

int n, a[MAXN];
map<int, int> mp;
vector<int> vec[MAXN];

int main(){
    int kase = 0;
    while(scanf("%d", &n) == 1 && n){
        if(kase)  printf("\n");
        kase = 1;
        int tmp, ans = 0;
        mp.clear();
        for(int i = 0; i < n; ++i){
            scanf("%d", &tmp);
            a[i] = tmp;
            ++mp[tmp];
            ans = max(ans, mp[tmp]);
        }
        for(int i = 0; i < ans; ++i)  vec[i].clear();
        int lur = 0;
        sort(a, a + n);
        for(int i = 0; i < n; ++i){
            vec[lur].push_back(a[i]);
            lur = (lur + 1) % ans;
        }
        printf("%d\n", ans);
        for(int i = 0; i < ans; ++i){
            for(int j = 0; j < vec[i].size(); ++j){
                if(j)  printf(" ");
                printf("%d", vec[i][j]);
            }
            printf("\n");
        }
    }
    return 0;
}

 

posted @ 2016-10-26 19:08  TianTengtt  阅读(122)  评论(0编辑  收藏  举报