def heap_sort(ary):
n = len(ary) #
first = int(n / 2 - 1) #
for start in range(first, -1, -1): # 3~0 revese
max_heapify(ary, start, n - 1) # from start
for end in range(n - 1, 0, -1):
ary[end], ary[0] = ary[0], ary[end]
max_heapify(ary, 0, end - 1)
return ary def max_heapify(ary, start, end):
root = start
while True:
child = root * 2 + 1
if child > end:
break
if child + 1 <= end and ary[child] < ary[child + 1]:
child += 1
if ary[root] < ary[child]:
ary[root], ary[child] = ary[child], ary[root]
root = child
else:
break def main():
ary = [6, 5, 3, 1, 8, 7, 2, 4]
heap_sort(ary) print(ary) main()

//Py自带的两种算法,一个sorted(ary)不影响本身结构,可ary.sort()就影响了

 def main():
# ary = [6, 5, 3, 1, 8, 7, 2, 4]
#heap_sort(ary) #print(ary) n = int(sys.stdin.readline())
ary = [] # 申明一个数组 while n > 0:
ary.append(int(raw_input())) # 输入的排成数组
n -= 1 ary.sort() #自带两种排序算法,.sort是真是变,sorter()是表面变
print '\n'.join(map(str, ary)) # map函数就是一个映射/转换,把list转换成string main()

学习

  挑战了一把当年讳莫如深的堆排,现在理解其实不难,就是一个使用二叉来减少比较次数的快速排序

  各种py排序算法

    http://wuchong.me/blog/2014/02/09/algorithm-sort-summary/

  熟悉了通过查看文档来学习使用python的相关函数

  熟悉调用其自生的函数库

Turbo Sort Add problem to Todo list Problem code: TSORT的更多相关文章

  1. Holes in the text Add problem to Todo list Problem code: HOLES

    import sys def count_holes(letter): hole_2 = ['A', 'D', 'O', 'P', 'Q', 'R'] if letter == 'B': return ...

  2. The Lead Game Add problem to Todo list Problem code: TLG

    '''def count_lead(first, second): if first > second: return 1, first - second elif first == secon ...

  3. 【CodeChef】Turbo Sort

    题目链接:Turbo Sort 用java自带O(NlogN)的排序就可以,java要特别注意输入输出.输入用BufferedReader,输出用printWriter.printWriter的速度比 ...

  4. Problem : 1002 ( A + B Problem II )

    经验总结:一定要注意输出的格式,字符的空格,空行,一定要观察清楚.如本题的最后一个输出结果后面没有空行.最后代码实现的时候需要判断一下,代码如下 !=n) cout<<endl; Prob ...

  5. 2013-2014 ACM-ICPC, NEERC, Southern Subregional Contest Problem B. Travelling Camera Problem set贪心

    Problem B. Travelling Camera Problem 题目连接: http://www.codeforces.com/gym/100253 Description Programm ...

  6. 几何入门合集 gym101968 problem F. Mirror + gym102082 Problem F Fair Chocolate-Cutting + gym101915 problem B. Ali and Wi-Fi

    abstract: V const & a 加速 F. Mirror 题意 链接 问题: 有n个人在y=0的平面上(及xoz平面).z=0平面上有一面镜子(边平行于坐标轴).z=a平面上有q个 ...

  7. Problem B The Blocks Problem(vector的使用)

    题目链接:Problem B 题意:有n块木块,编号为0~n-1,要求模拟以下4种操作(下面的a和b都是木块编号) 1. move a onto b: 把a和b上方的木块全部归位,然后把a摞在b上面. ...

  8. A+B Problem Plus and A-B Problem Plus and A*B Problem Plus

    //we have defined the necessary header files here for this problem. //If additional header files are ...

  9. Problem J. Joseph’s Problem 约瑟夫问题--余数之和

    链接:https://vjudge.net/problem/UVA-1363 题意:给出n  k,当 i 属于 1~n 时 ,求解 n% i 的和 n 和 k 的范围都是 1 到 10^9; 商相同 ...

随机推荐

  1. 在预装win8的电脑上换win7系统讲解

    现在买电脑,如果电脑预装的系统是win8系统,那么这个电脑的默认启动模式应该就是UEFI模式,现在UEFI模式正在逐渐取代传统模式.UEFI启动需要一个独立的分区,它将系统启动文件和操作系统本身隔离, ...

  2. 背包问题lingo求解

    大家好,我是小鸭酱,博客地址为:http://www.cnblogs.com/xiaoyajiang !背包问题 题目: 8件物品   重量分别为 1,3,4,3,3,1,5,10 价值分别为 2,9 ...

  3. Touch事件

    http://www.cnblogs.com/shawn-xie/archive/2012/12/07/2805582.html 前言 一个触屏网站到底和传统的pc端网站有什么区别呢,交互方式的改变首 ...

  4. qt 拖拽 修改大小(使用了nativeEvent和winEvent)

    http://www.cnblogs.com/swarmbees/p/5621543.html http://blog.sina.com.cn/s/blog_9e59cf590102w3r6.html

  5. QT中共享库的生成与使用

    一. 静态库的生成1. 测试目录: lib2. 源码文件名: mywindow.h, mywindow.cpp, 类MyWindow继承于QPushButton, 并将文字设置为"I'm i ...

  6. 64位调试器花费的时间比预期的要长(A 64-bit debugging operation is taking longer than expected)

    在stackoverflow上找到解决方案的: http://stackoverflow.com/questions/21329899/vs2013-professional-local-64-bit ...

  7. STLtoSVG,and SVG to Bmp

    先用这两个工具: Slic3R或者Skeinforge:这个两个工具的作用就是把STL文件切片为叠加的矢量图(SVG格式) 因为SVG是分层的,一层一层的把每层都转换成一张Bmp文件 听说ImageM ...

  8. BZOJ1211: [HNOI2004]树的计数

    1211: [HNOI2004]树的计数 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1245  Solved: 383[Submit][Statu ...

  9. hdu 1695 GCD(欧拉函数+容斥)

    Problem Description Given 5 integers: a, b, c, d, k, you're to find x in a...b, y in c...d that GCD( ...

  10. art.dialog

    关闭指定弹出窗: art.dialog({ id: 'hetong' }).close(); 关闭所有的iframe弹出窗,art.dia.close();