内存不够用,用计数排序可以解决问题。

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<list>
#include<deque>
#include<algorithm>
#include<stack>
#include<queue>
#include<cctype>
#include<sstream>
using namespace std;
#define pii pair<int,int>
typedef long long int LL;
const double eps=1e-;
const int INF=;
const int maxn=+;
int c[],n,x;
int main()
{
//freopen("in1.txt","r",stdin);
//freopen("out.txt","w",stdout);
while(scanf("%d",&n)==&&n)
{
memset(c,,sizeof(c));
for(int i=; i<n; i++)
{
scanf("%d",&x);
c[x]++;
}
int first=;
for(int i=; i<=; i++)
{
//cout<<"c"<<i<<':'<<c[i]<<endl;
if(c[i]>)
{
while(c[i]--)
{
if(first==)
{
first=;
printf("%d",i);
}
else
{
printf(" %d",i);
}
}
}
}
printf("\n");
}
return ;
}

11462 Age Sort(计数排序)的更多相关文章

  1. Uva-------(11462) Age Sort(计数排序)

    B Age Sort Input: Standard Input Output: Standard Output   You are given the ages (in years) of all ...

  2. counting sort 计数排序

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

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

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

  5. UVa 11462 Age Sort

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

  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. 《算法导论》——计数排序Counting Sort

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

  9. 计数排序与桶排序(bucket sort)

    Bucket Sort is a sorting method that subdivides the given data into various buckets depending on cer ...

随机推荐

  1. self-awareness is key in changing the way you think

    1: controlling the way you think is a manageable process The good news is that you have control over ...

  2. Squid 正向代理配置

    Squid 正向代理配置 1.删除主配置文件重写写入配置 rm -f /etc/squid/squid.conf 2.重新写入配置正向代理 vim /etc/squid/squid.conf # 监听 ...

  3. matlab第一个小应用

    今天安装了matlab,以前还是上线性代数的时候,老师让用过,以及水了一次数模的时候玩了一下.以前太年轻,总觉得这个用处不大虽然别人一直强调这个神器... 到了自己要用的时候才会意识到.大家可能也都听 ...

  4. oracle 导出

    一.导出csv文件 利用Oracle中的Spool缓冲池技术可以实现Oracle数据导出到文本文件. 1).在Oracle PL/SQL中输入缓冲开始命令,并指定输出的文件名: spool /tmp/ ...

  5. tensorFlow 神经网络2

    learnrate 太大容易跑飞,设置激活函数 可以一定程度上增加learnrate,不跑飞 self.saver = tf.train.Saver() 和 self.init_variable = ...

  6. python 操作mongoDB数据库

    网上关于python 操作mongoDB的相关文章相对不是很多,并且质量也不是很高!下面给出一个完整的 增删改查示例程序! #!/usr/bin/python # -*- coding: utf-8 ...

  7. PAT1023. Have Fun with Numbers (20)

    #include <iostream> #include <map> #include <algorithm> using namespace std; strin ...

  8. QT 使用QTcpServer QTcpSocket 建立TCP服务器端 和 客户端

    1.  如图客户端连接server后,server发送"hello tcp" 给客户端 2. 实例代码 -----------------------------------  s ...

  9. UOJ180 【UR #12】实验室外的攻防战

    本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/ ...

  10. UOJ283 直径拆除鸡

    本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/ ...