11462 Age Sort(计数排序)
内存不够用,用计数排序可以解决问题。
#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(计数排序)的更多相关文章
- Uva-------(11462) Age Sort(计数排序)
B Age Sort Input: Standard Input Output: Standard Output You are given the ages (in years) of all ...
- counting sort 计数排序
//counting sort 计数排序 //参考算法导论8.2节 #include<cstdio> #include<cstring> #include<algorit ...
- 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 ...
- 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 ...
- UVa 11462 Age Sort
解题报告:给若干个居民的年龄排序,年龄的范围在1到100之间,输入的总人数在0到200W.这题要注意的输入的文件约有25MB,而内存限制为2MB,所以如果人数是像200W这样多的话,甚至都不能把它们都 ...
- 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) 方法:先找出最大值最小值,之后统计每个数出现的次数,根据次数从小到大往数组里添加 计数排序法是一种不需要比 ...
- 《算法导论》——计数排序Counting Sort
今天贴出的算法是计数排序Counting Sort.在经过一番挣扎之前,我很纠结,今天这个算法在一些scenarios,并不是最优的算法.最坏情况和最好情况下,时间复杂度差距很大. 代码Countin ...
- 计数排序与桶排序(bucket sort)
Bucket Sort is a sorting method that subdivides the given data into various buckets depending on cer ...
随机推荐
- PyQt4 调用串口API pySerial API说明
pySerial API官方介绍链接 http://pyserial.readthedocs.io/en/latest/pyserial_api.html
- Easyui 遮罩实现方式
项目中在提交Ajax请求时,后台处理数据时间有点长,需要一个遮罩,就随便找了一个实现一下:包含两种方式,个人比较喜欢第二种 第一种: $("#saveMaterial").clic ...
- Centos配置sftp
sftp配置: ssh -V 使用ssh –V命令来查看openssh的版本,版本必须大于4.8p1,低于这个版本需要升级. 1.添加用户及用户组: groupadd sftp useradd -g ...
- iOS9 Search API 之 Spotlight
iOS9以后 有三种api提供搜搜方式 加强引导用户关注 我们的app及相关内容的方式 NSUserActivity Web Markup Core Spotlight 用法 前两种 实战操作性不够 ...
- VC6.0中添加库文件和头文件
附加头文件包含 VC6.0中: VC6.0默认include包含路径:Tools>Options>Directories>Include files. 对于特定项目的头文件包含,在“ ...
- matlab 读取nc
在这里做个记录,这几个是matlab用来读取.nc格式数据的函数.只是函数,参数和变量为了便于理解,取括号中的名字. fid=netcdf.open('fname','nowriter');%打开 ...
- flask实现模仿知乎
上个月花了一个月的时间学习flask框架实现了一个简陋的知乎,有提问,回答,写文章,个人信息页,个人信息修改等功能,因刚接触学习flask,后端代码实现很多冗余,依旧需要修改. github: htt ...
- Struts2笔记01——基础MVC架构(转)
原始内容:https://www.tutorialspoint.com/struts_2/basic_mvc_architecture.htm Apache Struts 2是用来创建企业级Java ...
- 生产&消费者模型
import queue,threading,time ,random q = queue.Queue() def producer(): count = 1 while count <11: ...
- POI 百万数据导出
poi 导出主类 package test; import java.io.File; import java.io.FileOutputStream; import java.lang.reflec ...