As Easy As A+B

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 70286    Accepted Submission(s): 29895

Problem Description
These days, I am thinking about a question, how can I get a problem as easy as A+B? It is fairly difficulty to do such a thing. Of course, I got it after many waking nights.
Give you some integers, your task is to sort these number ascending (升序).
You should know how easy the problem is now!
Good luck!
 
Input
Input contains multiple test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow. Each test case contains an integer N (1<=N<=1000 the number of integers to be sorted) and then N integers follow in the same line. 
It is guarantied that all integers are in the range of 32-int.
 
Output
For each case, print the sorting result, and one line one case.
 
Sample Input
2
3 2 1 3
9 1 4 7 2 5 8 3 6 9
 
Sample Output
1 2 3
1 2 3 4 5 6 7 8 9
 
Author
lcy
思路:手写快排,
#include<cstdio>
#include<set>
#include<iostream>
#include<functional>
#include<algorithm>
using namespace std;
void quick_sort(int a[], int low, int high)
{
if (low >= high)return;
int s = low, e = high, key = a[low];
while (s < e){
while (s < e && a[e] >= key)e--;
a[s] = a[e];
while (s < e && a[s] <= key)s++;
a[e] = a[s];
}
a[s] = key;
quick_sort(a, low, s - );
quick_sort(a, s + , high);
}
int main()
{
int a[];
int t; cin >> t;
while (t--) {
int n; cin >> n; for (int i = ; i < n; i++)
cin >> a[i];
quick_sort(a, , n - );
for (int i = ; i < n; i++){
if (i == n - )cout << a[i] << endl;
else cout << a[i] << " ";
} }
return ;
}

hdu 1040的更多相关文章

  1. hdu 1040 As Easy As A+B

    As Easy As A+B Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) T ...

  2. HDU 1040 As Easy As A+B(排序)

    As Easy As A+B Problem Description These days, I am thinking about a question, how can I get a probl ...

  3. HDU 1040 As Easy As A+B (排序。。。水题)

    题意:给定n个数,让你从小到大排序. 析:不说什么了. 代码如下: #include <cstdio> #include <iostream> #include <cst ...

  4. hdu 1040 As Easy As A+B(排序)

    题意:裸排序 思路:排序 #include<iostream> #include<stdio.h> #include<algorithm> using namesp ...

  5. HDU 1040 As Easy As A+B [补]

    今天去老校区找她,不想带电脑了,所以没时间A题了 /*******************************************************************/ As Ea ...

  6. HDU 1040.As Easy As A+B【排序】【如题(水!水!水!)】【8月24】

    As Easy As A+B Problem Description These days, I am thinking about a question, how can I get a probl ...

  7. HDU题解索引

    HDU 1000 A + B Problem  I/O HDU 1001 Sum Problem  数学 HDU 1002 A + B Problem II  高精度加法 HDU 1003 Maxsu ...

  8. 八大排序算法之六--交换排序—快速排序(Quick Sort)

    基本思想: 1)选择一个基准元素,通常选择第一个元素或者最后一个元素, 2)通过一趟排序讲待排序的记录分割成独立的两部分,其中一部分记录的元素值均比基准元素值小.另一部分记录的 元素值比基准值大. 3 ...

  9. 八大排序算法之五--交换排序—冒泡排序(Bubble Sort)

    基本思想: 在要排序的一组数中,对当前还未排好序的范围内的全部数,自上而下对相邻的两个数依次进行比较和调整,让较大的数往下沉,较小的往上冒.即:每当两相邻的数比较后发现它们的排序与排序要求相反时,就将 ...

随机推荐

  1. Spring Theme简单应用

    Spring MVC特性里由一个是关于Spring Theme主题的应用,所以写了个Demo 1.这里先看项目结构(Meven项目) 2.所需的POM依赖 <dependency> < ...

  2. Java开发笔记(九十二)文件通道的基本用法

    前面介绍的各色流式IO在功能方面着实强大,处理文件的时候该具备的操作应有尽有,可流式IO在性能方面不尽如人意,它的设计原理使得实际运行效率偏低,为此从Java4开始增加了NIO技术,通过全新的架构体系 ...

  3. leetcode343 Integer Break

    思路: 将n不断拆分3出来直至其小于或等于4. 实现: class Solution { public: int integerBreak(int n) { ] = {, , , }; ) retur ...

  4. Js onmouseover和onmouseout小特效

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...

  5. CSS 潜藏着的BFC

    在写样式时,往往是添加了一个样式,又或者是修改了某个属性,就达到了我们的预期. 而BFC就潜藏在其中,当你修改样式时,一不小心就能触发它而毫无察觉,因此没有意识到BFC的神奇之处. 什么是BFC(Bl ...

  6. OKHTTP 简单分析

    内部使用了OKIO库, 此库中Source表示输入流(相当于InputStream),Sink表示输出流(相当于OutputStream) 特点: ·既支持同步请求,也支持异步请求,同步请求会阻塞当前 ...

  7. vue学习图解

    vue2.0版本的学习图解个人心得!本文为原创禁止转载!!转载需要注明出处,谢谢合作!!!

  8. Python中的排序方法

    1 list.sort list.sort(key=None, reverse=False) 该方法只能用于list.就地排序,原来的list被修改.key的用法见下文.reverse控制降序还是生序 ...

  9. Loadrunner12 安装与卸载

    卸载:http://www.51testing.com/html/21/303921-216608.html 安装包下载: loadrunner12安装包下载:链接:https://pan.baidu ...

  10. 【Js 文件】 相关

    防止浏览器缓存 <script src="/js/common.js?t=<%=DateTime.Now.ToFileTime().ToString()%>>&quo ...