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 (0<n<=2000000), the total number of people. In the next line, there are integers indicating the ages. Input is terminated with a case where = 0. This case should not be processed.

Output

For each case, print a line with 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(计数排序)的更多相关文章

  1. 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 ...

  2. UVa 11462 Age Sort

    解题报告:给若干个居民的年龄排序,年龄的范围在1到100之间,输入的总人数在0到200W.这题要注意的输入的文件约有25MB,而内存限制为2MB,所以如果人数是像200W这样多的话,甚至都不能把它们都 ...

  3. counting sort 计数排序

    //counting sort 计数排序 //参考算法导论8.2节 #include<cstdio> #include<cstring> #include<algorit ...

  4. 11462 Age Sort(计数排序)

    内存不够用,用计数排序可以解决问题. #include<iostream> #include<cstdio> #include<cstdlib> #include& ...

  5. 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 ...

  6. COGS 1406. 邻居年龄排序[Age Sort,UVa 11462](水题日常)

    ★   输入文件:AgeSort.in   输出文件:AgeSort.out   简单对比时间限制:1 s   内存限制:2 MB [题目描述] Mr.Zero(CH)喜闻乐见地得到了一台内存大大增强 ...

  7. 计数排序(Count Sort )与插入排序(Insert Sort)

    计数排序法:计数数组适用于当前数组密集的情况.例如(2,3,5,4,2,3,3,2,5,4) 方法:先找出最大值最小值,之后统计每个数出现的次数,根据次数从小到大往数组里添加 计数排序法是一种不需要比 ...

  8. uva 10474 Where is the Marble? 计数排序

    题目给出一系列数字,然后问哪个数字是从小到大排在第几的,重复出现算第一个. 数据范围为10000,不大,完全可以暴力,sort不会超时. 但是由于以前做比赛时也遇到这种题目,没注意看数据范围,然后暴力 ...

  9. 《算法导论》——计数排序Counting Sort

    今天贴出的算法是计数排序Counting Sort.在经过一番挣扎之前,我很纠结,今天这个算法在一些scenarios,并不是最优的算法.最坏情况和最好情况下,时间复杂度差距很大. 代码Countin ...

随机推荐

  1. Android 路径大全

    1 内部存储路径为/data/data/youPackageName/ 目录结构 //返回cache文件对象 this.getCacheDir(); //返回databases下指定文件 this.g ...

  2. 1,linux基础知识以及新建虚拟机

    1,Windows图形界面只是在个人电脑上普及(dos界面):lunix是在服务器领域,服务器上绝对不出现图形化界面(命令行). 2,2.6.18  主板本,次版本,末版本 如果末版本积累到一定程序就 ...

  3. nyoj 1058部分和问题(DFS)

    部分和问题 时间限制:1000 ms  |  内存限制:65535 KB 难度:2   描述 给定整数a1.a2........an,判断是否可以从中选出若干数,使它们的和恰好为K.   输入 首先, ...

  4. 个人作业Week 2 ----------代码的规范和代码复审

    1.是否需要有代码规范 从个人理解的角度出发,我认为代码规范还可以细分为代码的风格还有代码的结构设计(就好比排版一类的) 以前在上C语言课程的时候就看到过,老师会在打“{”的时候进行一个换行,但是有些 ...

  5. ASP.NET MVC HtmlHelper用法集锦

    ASP.NET MVC HtmlHelper用法集锦 在写一个编辑数据的页面时,我们通常会写如下代码 1:<inputtype="text"value='<%=View ...

  6. Java中List、Collections实现梭哈游戏

    package ch8; import java.util.*; /** * Created by Jiqing on 2016/11/27. */ public class ShowHand { / ...

  7. EAPOL 协议

    EAPOL 协议 一.基本概念 EAPOL 的全称为 Extensible Authentication Protocol Over LAN,即 EAP Over Lan,也即基于局域网的扩展认证协议 ...

  8. openSUSE 国内镜像和镜像使用帮助 (zhuan)

    https://my.oschina.net/u/2475751/blog/631036?p={{currentPage-1}} https://lug.ustc.edu.cn/wiki/mirror ...

  9. nginx安装笔记

    双节点安装 1 节点一 1.1 目录 /usr/local cd /usr/local 1.2 openssl rpm -ql openssl /usr/share/doc/openssl-1.0.0 ...

  10. 【ros】Create a ROS package:package dependencies报错

    $rospack depends1 beginner_tutorials 报错:Erros:could notn call python function 'rosdep2.rospack.init_ ...