swust oj 1015
堆排序算法
编写程序堆排序算法。按照从小到大的顺序进行排序,测试数据为整数。
输入
第一行是待排序数据元素的个数; 第二行是待排序的数据元素。(提示:用小根堆)
输出
一趟堆排序的结果。
样例输入
10
50 36 41 19 23 4 20 18 12 22
样例输出
4 12 20 18 22 41 50 36 19 23
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cstdio>
using namespace std; void sift(int arr[],int low,int high)
{
int i=low,j=*i;
int tmp=arr[i];
while(j<=high)
{
if(j<high&&arr[j]>arr[j+]) //小的上浮,大的下沉
j++;
if(tmp>arr[j])
{
arr[i]=arr[j];
i=j;
j=*i;
}
else
break;
}
arr[i]=tmp;
} void Heapsort(int arr[],int n)
{
for(int i=n/;i>=;i--) //建立初始堆,第一趟
sift(arr,i,n);
} int main()
{
int n;
int arr[];
cin>>n;
for(int i=;i<=n;i++)
cin>>arr[i];
Heapsort(arr,n);
for(int i=;i<=n;i++)
cout<<arr[i]<<" ";
return ;
}
swust oj 1015的更多相关文章
- [Swust OJ 404]--最小代价树(动态规划)
题目链接:http://acm.swust.edu.cn/problem/code/745255/ Time limit(ms): 1000 Memory limit(kb): 65535 Des ...
- [Swust OJ 649]--NBA Finals(dp,后台略(hen)坑)
题目链接:http://acm.swust.edu.cn/problem/649/ Time limit(ms): 1000 Memory limit(kb): 65535 Consider two ...
- SWUST OJ NBA Finals(0649)
NBA Finals(0649) Time limit(ms): 1000 Memory limit(kb): 65535 Submission: 404 Accepted: 128 Descri ...
- [Swust OJ 1023]--Escape(带点其他状态的BFS)
解题思路:http://acm.swust.edu.cn/problem/1023/ Time limit(ms): 5000 Memory limit(kb): 65535 Descript ...
- [Swust OJ 1125]--又见GCD(数论,素数表存贮因子)
题目链接:http://acm.swust.edu.cn/problem/1125/ Time limit(ms): 1000 Memory limit(kb): 65535 Descriptio ...
- [Swust OJ 1126]--神奇的矩阵(BFS,预处理,打表)
题目链接:http://acm.swust.edu.cn/problem/1126/ Time limit(ms): 1000 Memory limit(kb): 65535 上一周里,患有XX症的哈 ...
- [Swust OJ 1026]--Egg pain's hzf
题目链接:http://acm.swust.edu.cn/problem/1026/ Time limit(ms): 3000 Memory limit(kb): 65535 hzf ...
- [Swust OJ 1139]--Coin-row problem
题目链接: http://acm.swust.edu.cn/contest/0226/problem/1139/ There is a row of n coins whose values are ...
- [Swust OJ 385]--自动写诗
题目链接:http://acm.swust.edu.cn/problem/0385/ Time limit(ms): 5000 Memory limit(kb): 65535 Descripti ...
随机推荐
- C#退出程序,退出任务管理器
//窗体关闭之前 this.FormClosing += (s, r) => { System.Environment.Exit(0); }; //窗体关闭 this.Closed += (s, ...
- PowerShell 显示气球提示框 1
#加载 Winform 程序集,使用Out-Null抑制输出 [system.Reflection.Assembly]::LoadWithPartialName('System.Windows.For ...
- 如何在IIS上发布网站 在阿里云服务器windows server2012r iis上部署.net网站
如何在IIS上发布网站 本片博客记录一下怎么用IIS发布一个网站,以我自己电脑上一个已经开发完成的网站为例: 1.打开项目 这是我电脑上的一个项目,现在我记录一下将这个项目发布到iis上的整个过程 ...
- FFmpeg: 一个简单测试手机解码效率的方法
先写一个获取当前时间戳的方法 long long GetNowMs() { struct timeval tv; gettimeofday(&tv, NULL); ; // 为了简化计算,否则 ...
- 【nodejs】exports 和 module.exports 的区别
require 用来加载代码,而 exports 和 module.exports 则用来导出代码.但很多新手可能会迷惑于 exports 和 module.exports 的区别,为了更好的理解 e ...
- Halcon 彩色图片通道分割处理
1.RGB通道:R红色,G绿色,B蓝色:R.G.B各占一个字节,取值范围在0—255:可代表的颜色数256*256*256==2^24 黑色区域是:R=G=B=0; 白色区域是:R=G=B=255 ...
- linux搭建FTP服务器并整合Nginx
操作系统:Centos7 1.1.服务器配置 # 关闭SELINUX,把SELINUX=enforcing改为SELINUX=disabled,reboot重启服务器生效 vim /etc/sysco ...
- vlc-ts
https://github.com/jiayayao/vlc_2.1.0-vs_2010 https://wenku.baidu.com/view/a0634d26336c1eb91a375d70. ...
- Python学习小组微信群公告页面
<简明 Python 教程>读经群,PDF地址:https://pan.baidu.com/s/1FK8s4cTfwWxSktOfS95ArQ,PyCharm-Edu地址:https:// ...
- VMware vCenter Server 6.5安装
实验环境: 数据中心操作系统 : Windows server 2008 R2(建议配置8G内存) 数据中心安装包版本: VMware vCenter Server 6.5 数据中心数据库: ...