UVA - 11100 The Trip, 2007
来源:互联网 发布:linux 格式化硬盘 编辑:程序博客网 时间:2024/06/06 00:05
1.题面
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=21322
2.题意
给你n个数字,
1.把他们分成尽可能少的严格递增序列
2.在保证序列数尽可能少的情况下,希望能使元素最多的序列中的元素数量尽可能少
3.思路
排序后得到序列a
统计处每个元素的数量s[i],显而易见max(s[i])是第一个输出
设 k = max(i)
从0~k中的a[i]以k为间隔输出元素知道序列末尾
显而易见输出有k行
又因为k = max(i),所以序列必然是递增的
4.代码
/***************************************************************** > File Name: Cpp_Acm.cpp > Author: Uncle_Sugar > Mail: uncle_sugar@qq.com > Created Time: 2016年05月11日 星期三 21时36分19秒*****************************************************************/# include <cstdio># include <cstring># include <cctype># include <cmath># include <cstdlib># include <climits># include <iostream># include <iomanip># include <set># include <map># include <vector># include <stack># include <queue># include <algorithm>using namespace std;const int debug = 1;const int size = 100000 + 10; const int INF = INT_MAX>>1;typedef long long ll;int arr[size];int main(){std::ios::sync_with_stdio(false);cin.tie(0);int i,j;int n,ncase=0;while (cin>>n&&n){if (ncase++)cout << '\n';for (i=0;i<n;i++){cin >> arr[i];}sort(arr,arr+n);int ans = 0,cnt = 1;for (i=1;i<n;i++){if (arr[i]==arr[i-1])cnt++;else cnt = 1;ans = max(ans,cnt);}cout << ans << endl;for (i=0;i<ans;i++){for (j=i;j<n;j+=ans){cout << arr[j] << (j+ans>=n?'\n':' ');}}}return 0;}
0 0
- UVA 11100 The Trip, 2007
- UVa 11100 - The Trip, 2007
- UVa 11100 - The Trip, 2007
- uva 11100 - The Trip, 2007
- uva 11100 - The Trip, 2007
- UVA 11100 - The Trip, 2007
- uva 11100 The Trip, 2007
- UVA 11100 - The Trip, 2007
- UVa:11100 The Trip, 2007
- uva 11100 The Trip, 2007
- UVa 11100 - The Trip, 2007
- UVA - 11100 The Trip, 2007
- uva--11100The Trip, 2007
- UVA 11100 The Trip, 2007
- UVA - 11100 The Trip, 2007
- UVa 11100 - The Trip, 2007
- uva 11100 The Trip, 2007
- uva 11100 The Trip, 2007
- 文件的分割与合并
- (MVP+RxJava+Retrofit)解耦+Mockito单元测试 经验分享
- springMVC搭建总结
- Android自定义视图动画(一)
- Opencv3.1使用教程(一)ubuntu 14.04 安装Opencv3.1.0 (包含opencv_contrib模块)
- UVA - 11100 The Trip, 2007
- spark 自带的例子在eclipse下运行的方法
- AndroidStudio 快速集成fastjson和注解
- 2016"百度之星" - 测试赛 1002 列变位法解密 (模拟)
- 取数游戏 贪心
- 水波纹效果
- 消息对列的操作
- C++新特性
- 增强学习Reinforcement Learning经典算法梳理1:policy and value iteration