zoukankan      html  css  js  c++  java
  • UVa 11100 旅行2007

    https://vjudge.net/problem/UVA-11100

    题意:

    给定n个正整数,把它们划分成尽量少的严格递增序列,尽量均分。

    思路:

    因为必须严格递增,所以先统计每个数字出现的次数,次数最多的就是要划分的序列个数。

    接下来每次用最多次数作为步长划分,很巧妙。

     1 #include<iostream>
     2 #include<string>
     3 #include<cstring>
     4 #include<algorithm>
     5 #include<vector>
     6 using namespace std;
     7 
     8 const int maxn = 10000 + 5;
     9 int a[maxn];
    10 int vis[maxn];
    11 vector<int> c[maxn];
    12 
    13 int n;
    14 
    15 int main()
    16 {
    17     //freopen("D:\txt.txt", "r", stdin);
    18     int kase = 0;
    19     while (cin >> n && n)
    20     {
    21         if (kase)   cout << endl;
    22         kase = 1;
    23         memset(vis, 0, sizeof(vis));
    24         for (int i = 1; i <= n; i++)
    25         {
    26             cin >> a[i];
    27             vis[a[i]]++;
    28         }
    29         int cnt = 0;
    30         for (int i = 1; i <= n; i++)
    31         {
    32             cnt = max(cnt, vis[a[i]]);
    33         }
    34         sort(a+1, a + n + 1);
    35         cout << cnt << endl;
    36         for (int i = 1; i <= cnt; i++)
    37         {
    38             int first = 1;
    39             for (int j = i; j <= n; j += cnt)
    40             {
    41                 if (first)
    42                 {
    43                     cout << a[j];
    44                     first = 0;
    45                 }
    46                 else   cout << " " << a[j];
    47             }
    48             cout << endl;
    49         }
    50     }
    51 }
  • 相关阅读:
    Git之不明觉厉11-利其器source tree
    GUI for git|SourceTree|入门基础
    UIButton
    NSDictionary
    注释方法、代码块加快捷键注释
    UIActionSheet
    UIActivityIndicatorView
    UIPickerView
    UIImageView
    UIAlertView
  • 原文地址:https://www.cnblogs.com/zyb993963526/p/6533042.html
Copyright © 2011-2022 走看看