codechef Turbo Sort 题解
Input
t – the number of numbers in list, then t lines follow [t <= 10^6].
Each line contains one integer: N [0 <= N <= 10^6]
Output
Output given numbers in non decreasing order.
Example
Input:
5
5
3
6
7
1
Output:
1
3
5
6
7
#include<stdio.h>
#include <iostream>
#include <algorithm>
using namespace std; int TurboSort()
{
int T = 0, num = -1, c = 0, j = 0;
scanf("%d\n", &T);
char buffer[1000000];
int *A = new int[T];
while ((c = fread(buffer, 1, 1000000, stdin)) > 0)
{
for (int i = 0; i < c; i++)
{
if (buffer[i] == '\n')
{
A[j++] = num;
num = -1;
}
else
{
if (-1 == num) num = buffer[i] - '0';
else num = num * 10 + buffer[i] - '0';
}
}
}
if (-1 != num) A[T-1] = num;
sort(A, A+T); for (int i = 0; i < T; i++)
{
printf("%d\n", A[i]);//使用cout会超时,最少慢5倍
}
delete [] A;
return 0;
}
codechef Turbo Sort 题解的更多相关文章
- 【CodeChef】Turbo Sort
题目链接:Turbo Sort 用java自带O(NlogN)的排序就可以,java要特别注意输入输出.输入用BufferedReader,输出用printWriter.printWriter的速度比 ...
- SPOJ #500. Turbo Sort
Sorting is not an out-dated topic. My own in-place qsort got TLE... so, I simply called stl::sort() ...
- Turbo Sort Add problem to Todo list Problem code: TSORT
def heap_sort(ary): n = len(ary) first = int(n / 2 - 1) for start in range(first, -1, -1): # 3~0 rev ...
- Codechef Racing Horses题解
找一个数组中两数之间最小的不同值. 思路: 1 排序 2 后前相减,比較得到最小不同值 三个数甚至很多其它数之间的不同值都是这么求了,时间效率都是O(nlgn) -- 排序使用的时间 原题: http ...
- LuoguP7259 [COCI2009-2010#3] SORT 题解
Content 请编写一个"频率排序器".输入一个 长度为 \(n\) 的数列 \(A=\{a_1,a_2,\dots,a_n\}\),要求: 按照每个数的出现次数降序排列. 如果 ...
- codechef Arranging Cup-cakes题解
Arranging Cup-cakes Our Chef is catering for a big corporate office party and is busy preparing diff ...
- Codechef Nuclear Reactors 题解
There are K nuclear reactor chambers labelled from 0 to K-1. Particles are bombarded onto chamber 0. ...
- HDU 1425 sort 题解
选择出数列中前k个最大的数. 这里由于数据特殊.所以能够使用hash表的方法: #include <cstdio> #include <algorithm> #include ...
- Hdoj 1425.sort 题解
Problem Description 给你n个整数,请按从大到小的顺序输出其中前m大的数. Input 每组测试数据有两行,第一行有两个数n,m(0<n,m<1000000),第二行包含 ...
随机推荐
- 利用XPath解析带有xmlns的XML文件
在.net中,编写读取xml 的程序中提示"未将对象引用设置到对象的实例",当时一看觉得有点奇怪.为什么在读取xml数据的时候也要实例化一个对象.google了才知道,xml文件中 ...
- [转] 小tip: 使用CSS将图片转换成模糊(毛玻璃)效果 ---张鑫旭
by zhangxinxu from http://www.zhangxinxu.com本文地址:http://www.zhangxinxu.com/wordpress/?p=3804 去年盛夏之时, ...
- 关于谷歌浏览器下自动填写密码的bug
有的时候我们需要用到h5中input的新类型,type=password 这个可以很好的将输入的内容变成圆点,但是这样做也有一个小bug就是在某些我们不希望自动保存密码的页面中,也会出现浏览器自动帮我 ...
- 配置并学习微信JS-SDK(2)—扫一扫接口http://www.qq210.com/shoutu/android
http://www.qq210.com/shoutu/android //c_开头的js变量是服务器传过来的 var c_access_token = "<?=$access_tok ...
- python消息队列snakemq使用总结
Python 消息队列snakemq总结 最近学习消息总线zeromq,在网上搜了python实现的消息总线模块,意外发现有个消息队列snakemq,于是拿来研究一下,感觉还是很不错的,入手简单使用也 ...
- jdk各个版本
http://www.cnblogs.com/langtianya/p/3757993.html
- 前端开发福音!阿里Weex跨平台移动开发工具开源-b
阿里巴巴今天在Qcon大会上宣布跨平台移动开发工具Weex开放内测邀请.Weex能够完美兼顾性能与动态性,让移动开发者通过简捷的前端语法写出Native级别的性能体验,并支持iOS.安卓.YunOS及 ...
- Ireport 报表导出 Poi + ireport 导出pdf, word ,excel ,htm
Ireport 报表导出 Poi + ireport 导出pdf, doc ,excel ,html 格式 下面是报表导出工具类reportExportUtils 需要导出以上格式的报表 只需要调用本 ...
- LA 4975
回文串的题,求最大的双重回文串: 重新复习了一下manacher算法: 代码: #include<cstdio> #include<cstring> #include<a ...
- (转载)MySQL LIKE 用法:搜索匹配字段中的指定内容
(转载)http://www.5idev.com/p-php_mysql_like.shtml MySQL LIKE 语法 LIKE 运算符用于 WHERE 表达式中,以搜索匹配字段中的指定内容,语法 ...