zoukankan      html  css  js  c++  java
  • UVA11100- The Trip, 2007

    题目链接


    题意:给定n个正整数。把它们划分成尽量少的严格递增序列(前一个数必须小于后一个数)。输出序列个数的最小值k和这k个序列。

    思路:出现次数最多的个数就是序列的个数。输出比較麻烦。但我们仅仅要每k个数输出一个数字,那么最后就能够将全部序列都输出来了。

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    
    using namespace std;
    
    const int INF = 1000000;
    const int MAXN = 10005;
    
    int n;
    int arr[MAXN], num[MAXN];
    
    int main() {
        int t = 0;
        while (scanf("%d", &n) && n) {
            memset(num, 0, sizeof(num));
            for (int i = 0; i < n; i++) { 
                scanf("%d", &arr[i]); 
                num[arr[i]]++; 
            }
            arr[n] = INF;
            int Max = 0, cnt = 0, temp = 0;
            for (int i = 0; i < MAXN; i++) {
                if (num[i] > cnt) {
                    cnt = num[i]; 
                    temp = i;
                } 
            }
            Max = num[temp];
            if (t) 
                printf("
    ");  
            t = 1; 
            printf("%d
    ", Max);
    
            sort(arr, arr + n); 
            for (int i = 0; i < Max; i++) {
                printf("%d", arr[i]);
                for (int j = i + Max; j < n; j += Max) {
                        printf(" %d", arr[j]);  
                }
                printf("
    "); 
            }
        }
        return 0;
    }


    版权声明:本文博客原创文章。博客,未经同意,不得转载。

  • 相关阅读:
    为aptget设置http代理[转]
    tty&pty
    Overfencing
    ubuntu修改runlevel
    ls l文件类型[转]
    ubuntu文字界面与图形界面切换
    ubuntu没有/etc/inittab文件
    linux一些缩写的意思
    redhat server 5.4安装中文
    关闭linux警报
  • 原文地址:https://www.cnblogs.com/lcchuguo/p/4688157.html
Copyright © 2011-2022 走看看