UVA - 11100 The Trip, 2007
2016-05-11 21:50
274 查看
1.题面
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=213222.题意
给你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; }
相关文章推荐
- 无人机视频影像几何校正
- UVA 10652 Board Wrapping 凸包
- Android内存泄漏
- bp算法推导过程
- Android性能优化之Java代码优化
- TQ210学习笔记——uboot代码搬移
- STL 源码剖析 String类
- 先来先服务和短作业优先算法
- 第一节:.net开发环境变量
- Oracle用户,权限,角色以及登录管理 scoot 授权
- 面试之路(31)-操作系统之信号量
- android NDK开发编译C++文件出现Type 'jint' could not be resolved和Unresolved inclusion: <jni.h>的解决办法
- openGL 填充样式
- Android获取图片资源的4种方式
- 面试之路(31)-操作系统之信号量
- 面试之路(31)-操作系统之信号量
- 编译安装zabbix3.0 并且与mysql分离
- 面试时如何谈自己做过的项目
- 如何进行svn relocate 操作
- weblogic配置:<prefer-web-inf-classes>true</prefer-web-inf-classes>