【CodeChef】Turbo Sort

题目链接:Turbo Sort

用java自带O(NlogN)的排序就可以,java要特别注意输入输出。输入用BufferedReader,输出用printWriter。printWriter的速度比System.out快很多,参考StackOverflow

代码:

 1 import java.io.BufferedOutputStream;
 2 import java.io.BufferedReader;
 3 import java.io.InputStreamReader;
 4 import java.io.PrintWriter;
 5 import java.util.Arrays;
 6
 7
 8 public class Main {
 9     public static void main(String[] args) throws Exception{
10         // TODO Auto-generated method stub
11         BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
12         int N = Integer.parseInt(bf.readLine());
13         int[] ar = new int[N];
14         for(int i = 0;i < N;i++){
15             ar[i] = Integer.parseInt(bf.readLine());;
16         }
17         Arrays.sort(ar);
18
19         PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));
20         for(int i = 0;i < N;i++)
21             pw.println(ar[i]);
22         pw.flush();
23     }
24
25 }

【CodeChef】Turbo Sort

时间: 2024-10-09 19:28:19

【CodeChef】Turbo Sort的相关文章

【CodeChef】Factorial(n!末尾0的个数)

The most important part of a GSM network is so called Base Transceiver Station (BTS). These transceivers form the areas called cells (this term gave the name to the cellular phone) and every phone connects to the BTS with the strongest signal (in a l

【HackerRank】Insertion Sort Advanced Analysis(归并排序求数列逆序数对)

Insertion Sort is a simple sorting technique which was covered in previous challenges. Sometimes, arrays may be too large for us to wait around for insertion sort to finish. Is there some other way we can calculate the number of times Insertion Sort

【CodeChef】Small factorials(BigInteger笔记)

You are asked to calculate factorials of some small positive integers. Input An integer t, 1<=t<=100, denoting the number of testcases, followed by t lines, each containing a single integer n, 1<=n<=100. Output For each integer n given at inpu

【CodeChef】Enormous Input Test

The purpose of this problem is to verify whether the method you are using to read input data is sufficiently fast to handle problems branded with the enormous Input/Output warning. You are expected to be able to process at least 2.5MB of input data p

【leetcode】905. Sort Array By Parity

题目如下: 解题思路:本题和[leetcode]75. Sort Colors类似,但是没有要求在输入数组本身修改,所以难度降低了.引入一个新的数组,然后遍历输入数组,如果数组元素是是偶数,插入到新数组头部,否则追加到尾部. 代码如下: class Solution(object): def sortArrayByParity(self, A): """ :type A: List[int] :rtype: List[int] """ res =

【LeetCode】排序 sort(共20题)

p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica } [56]Merge Intervals [57]Insert Interval [75]Sort Colors [147]Insertion Sort List [148]Sort List [164]Maximum Gap [179]Largest Number [242]Valid Anagram [252]Meeting Rooms (2018年11月22日,为

【CodeChef】Querying on a Grid(分治,最短路)

[CodeChef]Querying on a Grid(分治,最短路) 题面 Vjudge CodeChef 题解 考虑分治处理这个问题,每次取一个\(mid\),对于\(mid\)上的三个点构建最短路径树(因为保证了最短路唯一所以是树). 如果两点之间的最短路径跨越了\(mid\),那么必定有\(dis[u]+dis[v]\)的和就是最短路径长度. 那么我们在分治过程中考虑每一个\(mid\),取其中\(dis[u]+dis[v]\)的最小值,这样子就很容易可以找到最短路径长度. 然后知道了

【JavaScript】利用sort()函数与文件碎片实现表格的前端排序,兼容IE6原生态

表格排序在网页的应用也很多,尤其是一些信息系统输出一个密密麻麻的表格给人看,客户肯定会提出表格排序的要求.很多人定式思维地认为表格的排序一定要通过数据库后端进行交互,使用带order by asc/desc的语句去实现,然后再利用ajax似乎很完美似得.其实根本就不用与数据库打交道.在前端给出任意一个表格,都能够利用sort()函数与文件碎片实现表格的前端排序.在jquery里面是有一个advanceTable的插件做这件事,但是这个插件相当不好的是什么呢?与平常的插件一样,代码写得天花龙凤,没

【LeetCode】Insertion Sort List

题目 Sort a linked list using insertion sort. 解答 链表无法像数组那样从后往前依次比较插入,只能从前往后:在链表首部添加一个哨兵可以稍微简化下代码,代码如下: /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = null; * } * }