uva11100

来源:互联网 发布:js字符串替换换行符 编辑:程序博客网 时间:2024/05/17 02:41

题目的意思就是给出n个数字,尽量排成多个的递增序列。

序列的个数就是里面重复出现次数最多的数字的出现次数(因为每个序列只能房一个这个数)。

然后把排序完后的序列。分割出这么多个子序列就行了。。


ac代码:


#include<iostream>#include<algorithm>using namespace std;const int N = 10005;int a[N];int main() {    int n,t = 0;    while(cin >> n && n) {        t++;        if(t != 1)            cout << endl;        for(int i = 0 ; i < n; i++) {            cin >> a[i];        }        sort(a, a + n);        int temp = a[0];        int count = 1;        int m = -1;        for(int i = 1; i <n; i++){            if(a[i]==temp)                count++;            else {                temp = a[i];                count = 1;            }            if(count > m)                m = count;        }        cout << m << endl;        for(int i = 1; i <= m; i++)        {            int flag=0;            for(int j = n- i; j >= 0; j -= m)            {                if(flag==0)                {                    cout << a[j];                    flag=1;                }                else                {                    cout << " "<<a[j];                }            }            cout << endl;        }    }    return 0;}


0 0
原创粉丝点击