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. Python ftplib

    http://automationtesting.sinaapp.com/blog/m_ftplib https://docs.python.org/2/library/ftplib.html 概述 ...

  2. CANopen笔记1

    CAN现场总线只定义了OSI网络模型的第一层(物理层) 和第二层(数据链路层) ,而这两层一般已被CAN硬件完全实现了.由于没有规定应用层,本身并不完整,需要一个高层协议来定义CAN报文中的11/29 ...

  3. Create XO Checker Game With Oracle Forms

    Created XO Checker game in Oracle Forms and sharing its FMB (source code) for reference so that you ...

  4. shell 随机从文件中抽取若干行

    shuf -n5 main.txt sort -R main.txt | head -5 awk -vN=5 -vC="`wc -l file`" 'BEGIN{srand();w ...

  5. CUBRID学习笔记 4 端口和win7下连接数据库cubrid教程

    都是官方的文档 ,水平有限, 大家可以看原文. http://www.cubrid.org/wiki_tutorials/entry/connecting-to-a-remote-cubrid-dat ...

  6. table布局注意点

    1.同行等高. 2.宽度自动调节(table-layout:fixed;). 3.处理垂直居中又是神器 参考链接: http://www.blueidea.com/tech/web/2008/6257 ...

  7. 防止SQL注入问题

    -----解决方案--------------------------------------------------------过滤URL中的一些特殊字符,动态SQL语句使用PrepareState ...

  8. iOS - UITouch

    前言 NS_CLASS_AVAILABLE_IOS(2_0) @interface UITouch : NSObject @available(iOS 2.0, *) public class UIT ...

  9. JavaScript 点击图片放大功能

    <!doctype html> <html> <head> <meta charset="utf-8" /> <title&g ...

  10. poj3449Geometric Shapes

    链接 繁琐. 处理出来所有的线段,再判断相交. 对于正方形的已知对角顶点求剩余两顶点 (列出4个方程求解) p[].x=(p[].x+p[].x+p[].y-p[].y)/; p[].y=(p[].y ...