UVa 11100 旅行2007
生活随笔
收集整理的這篇文章主要介紹了
UVa 11100 旅行2007
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
https://vjudge.net/problem/UVA-11100
題意:
給定n個(gè)正整數(shù),把它們劃分成盡量少的嚴(yán)格遞增序列,盡量均分。
?
思路:
因?yàn)楸仨殗?yán)格遞增,所以先統(tǒng)計(jì)每個(gè)數(shù)字出現(xiàn)的次數(shù),次數(shù)最多的就是要?jiǎng)澐值男蛄袀€(gè)數(shù)。
接下來每次用最多次數(shù)作為步長劃分,很巧妙。
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 }?
轉(zhuǎn)載于:https://www.cnblogs.com/zyb993963526/p/6533042.html
總結(jié)
以上是生活随笔為你收集整理的UVa 11100 旅行2007的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Windows 窗体设计器中的设计时错误
- 下一篇: golang使用reflects调用方法