Uva-------(11462) Age Sort(计数排序)
|
B |
Age Sort Input: Standard Input Output: Standard Output |
You are given the ages (in years) of all people of a country with at least 1 year of age. You know that no individual in that country lives for 100 or more years. Now, you are given a very simple task of sorting all the ages in ascending order.
Input
There are multiple test cases in the input file. Each case starts with an integer n (0<n<=2000000), the total number of people. In the next line, there are n integers indicating the ages. Input is terminated with a case where n = 0. This case should not be processed.
Output
For each case, print a line with n space separated integers. These integers are the ages of that country sorted in ascending order.
Warning: Input Data is pretty big (~ 25 MB) so use faster IO.
Sample Input Output for Sample Input
|
5 3 4 2 1 5 5 2 3 2 3 1 0 |
1 2 3 4 5 1 2 2 3 3 |
Note: The memory limit of this problem is 2 Megabyte Only.
Problem Setter: Mohammad Mahmudur Rahman
Special Thanks: Shahriar Manzoor
数据大,内存小,而数据值的范围有限,适合运用计数排序求解...
代码:
#include<cstdio>
#include<cstring>
/*计数排序*/
int main()
{
int n,hash[],val;
while(~scanf("%d",&n)&&n)
{
memset(hash,,sizeof(hash));
for(int i=;i<n;i++)
{
scanf("%d",&val);
hash[val]++;
}
int flag=true;
for(int i=; i<=; i++)
{
for(int j=;j<=hash[i];j++)
{
if(flag)
{
printf("%d",i);
flag=false;
}
else printf(" %d",i);
}
}
puts("");
}
return ;
}
Uva-------(11462) Age Sort(计数排序)的更多相关文章
- UVA 11462 Age Sort(计数排序法 优化输入输出)
Age Sort You are given the ages (in years) of all people of a country with at least 1 year of age. Y ...
- UVa 11462 Age Sort
解题报告:给若干个居民的年龄排序,年龄的范围在1到100之间,输入的总人数在0到200W.这题要注意的输入的文件约有25MB,而内存限制为2MB,所以如果人数是像200W这样多的话,甚至都不能把它们都 ...
- counting sort 计数排序
//counting sort 计数排序 //参考算法导论8.2节 #include<cstdio> #include<cstring> #include<algorit ...
- 11462 Age Sort(计数排序)
内存不够用,用计数排序可以解决问题. #include<iostream> #include<cstdio> #include<cstdlib> #include& ...
- ACM比赛(11462 Age Sort)
You are given the ages (in years) of all people of a country with at least 1 year of age. You know t ...
- COGS 1406. 邻居年龄排序[Age Sort,UVa 11462](水题日常)
★ 输入文件:AgeSort.in 输出文件:AgeSort.out 简单对比时间限制:1 s 内存限制:2 MB [题目描述] Mr.Zero(CH)喜闻乐见地得到了一台内存大大增强 ...
- 计数排序(Count Sort )与插入排序(Insert Sort)
计数排序法:计数数组适用于当前数组密集的情况.例如(2,3,5,4,2,3,3,2,5,4) 方法:先找出最大值最小值,之后统计每个数出现的次数,根据次数从小到大往数组里添加 计数排序法是一种不需要比 ...
- uva 10474 Where is the Marble? 计数排序
题目给出一系列数字,然后问哪个数字是从小到大排在第几的,重复出现算第一个. 数据范围为10000,不大,完全可以暴力,sort不会超时. 但是由于以前做比赛时也遇到这种题目,没注意看数据范围,然后暴力 ...
- 《算法导论》——计数排序Counting Sort
今天贴出的算法是计数排序Counting Sort.在经过一番挣扎之前,我很纠结,今天这个算法在一些scenarios,并不是最优的算法.最坏情况和最好情况下,时间复杂度差距很大. 代码Countin ...
随机推荐
- 关于directX最近的学习方案
目标:弄清楚如何渲染一个地形,以及人物坐标以及摄像机方向,弄清四大矩阵原理 实践: 1.再次学习矩阵相关知识 2.实现红龙本书的地形 3.搜寻这方面资料书籍
- dev RichText高亮
需要引用的DLL DevExpress.CodeParser DevExpress.Office DevExpress.RichEdit DevExpress.XtraRichEdit MySyn ...
- Using Pre-Form Trigger In Oracle Forms
Pre-Form trigger in Oracle Forms fires during the form start-up, before forms navigates to the first ...
- ctrl+z暂停任务
(1) CTRL+Z挂起进程并放入后台 (2) jobs 显示当前暂停的进程 (3) bg %N 使第N个任务在后台运行(%前有空格) (4) fg %N 使第N个任务在前台运行 默认bg,fg不带% ...
- python_way,day8 面向对象【多态、成员--字段 方法 属性、成员修饰符、特殊成员、异常处理、设计模式之单例模式、模块:isinstance、issubclass】
python_way day8 一.面向对象三大特性: 多态 二.面向对象中的成员 字段.方法属性 三.成员修饰符 四.特殊成员 __init__.__doc__.__call__.__setitem ...
- Servlet学习
编写Servlet应该注意的一些细节: 1: 由于客户端是通过URL地址访问web服务器中的资源,所以Servlet程序若想被外界访问,必须把servlet程序映射到一个URL地址上,这个工作在web ...
- 使jQuqer更高效的方法
讨论 jQuery 和 javascript 性能的文章并不罕见.然而,本文我计划总结一些速度方面的技巧和我本人的一些建议,来提升你的 jQuery 和 javascript 代码.好的代码会带来速度 ...
- 《转》Ubuntu 12.04常用的快捷键
Ubuntu 12.04常用的快捷键 超级键操作 1.超级键(Win键)–打开dash. www.2cto.com 2.长按超级键– 启动Launcher.并快捷键列表. 3.按住 ...
- iOS - OC NSCalendar 日历
前言 @interface NSCalendar : NSObject <NSCopying, NSSecureCoding> NSCalendar 对世界上现存的常用的历法进行了封装,既 ...
- iOS - Swift NSEnumerator 迭代器
前言 public class NSEnumerator : NSObject, NSFastEnumeration 1.迭代器 let arr:NSArray = ["bei", ...