uva11100 贪心

#include <iostream>
#include <stdio.h>
#include <cstring>
#include <vector>
#include <algorithm>
int Int[10010];
int visit[100010];
using namespace std;
int main()
{
    int n;
    while(cin>>n&&n)
    {
        memset(visit,0,sizeof(visit));
        for(int i=0; i<n; i++)
            cin>>Int[i];
        sort(Int,Int+n);
        int k=1,max=1;
        int check=Int[0];
        for(int i=1; i<n; i++)
        {
            if(Int[i]==Int[i-1])
                k++;
            else
                k=1;
            if(max<k)
                max=k;
        }
        cout<<max<<endl;
        int tt;
        for(int i=0; i<max; i++) //  最坏情况所有的数都相等,时间复杂度为O(N^2);
        {

            for(int j=i; j<n; j+=max)
            {
                if(!visit[j]&&tt!=Int[j])
                {
                    if(i==j)
                        cout<<Int[j];
                    else
                        cout<<" "<<Int[j];
                }
            }
            cout<<endl;
        }
        /*   cout<<*unique(q1[0],Int+n)<<endl;
          for(int i=0;i<n;i++)
             cout<<Int[i]<<" ";
          cout<<endl;
         for(int i=0;i<n;i++)
         {
             int *temp=unique(q1[0],Int+n);
             if(temp==Int+n)
             {
                 k++;
                 q2[i]=temp;
                 break;
             }
             else
             {
                 k++;
                 q1[i]=q2[i];
                 q2[i]=temp;
             }
         }
         cout<<k<<endl;
         for(int i=0;i<k;i++)
         {
             for(int *j=q1[i];j<q2[i];j++)
             {
                 cout<<*j<<" ";
             }
             cout<<endl;
         }*/
        // cout<<endl;
    }
    return 0;
}
View Code

最多包数就是数字重复最多的次数。

posted @ 2014-10-31 13:32  名牌果果  阅读(205)  评论(0编辑  收藏  举报