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),第二行包含 ...
随机推荐
- 纯javascript联动的例子
有人想要学习下纯javascript联动的一些技巧,我这里就以日期的联动为例,附上一些代码至于复杂的省市区联动,不建议用纯javascript的,而是用ajax的方式,该不在此讨论范围内,想要了解aj ...
- 【转】深入 char * ,char ** ,char a[ ] ,char *a[] 内核
原文出处:http://blog.csdn.net/daiyutage/article/details/8604720 C语言中由于指针的灵活性,导致指针能代替数组使用,或者混合使用,这些导致了 ...
- objective-C: nonatomic retain copy assgin 等属性详解
http://my.oschina.net/u/728866/blog/90798 property,可以提供的功能有:提供成员变量的访问方法的声明.控制成员变量的访问权限.控制多线程时成员变量的访问 ...
- CMD 模块定义规范
在 Sea.js 中,所有 JavaScript 模块都遵循 CMD(Common Module Definition) 模块定义规范.该规范明确了模块的基本书写格式和基本交互规则. 在 CMD 规范 ...
- BZOJ 2226 LCMSum
Description Given \(n\), calculate the sum \(LCM(1,n) + LCM(2,n) + \cdots + LCM(n,n)\), where \(LCM( ...
- java rest版简单的webservice
目前的webservice风格,rest应该是其中一种 还有种就是soap,rest是轻量级的,越来越流行.下面举一个简单例子说明下rest的用法. 1. 准备ws的jar和spring的jar,如何 ...
- Android开源项目发现--- 工具类数据库ORM篇(持续更新)
orm的db工具类,简化建表.查询.更新.插入.事务.索引的操作 1. greenDAO Android Sqlite orm的db工具类 项目地址:https://github.com/greenr ...
- lc面试准备:Regular Expression Matching
1 题目 Implement regular expression matching with support for '.' and '*'. '.' Matches any single char ...
- Constructing Roads(SPFA+邻接表)
题目描述 Long long ago, There was a country named X, the country has N cities which are numbered from 1 ...
- nginx -- nginx平台初探(100%)
初探nginx架构(100%) 众所周知,nginx性能高,而nginx的高性能与其架构是分不开的.那么nginx究竟是怎么样的呢?这一节我们先来初识一下nginx框架吧. nginx在启动后,在un ...