1098 Insertion or Heap Sort (25 分)(堆)
这里的第二序列相当于是排序还没拍好的序列
对于第二个样例的第二个序列其实已经是大顶堆了 然后才进行的堆排序 知道这个就好做了
#include<bits/stdc++.h> using namespace std;
vector<int>a,b;
int n;
void downAdjust(int low,int high)
{
int i=low;
int j=i*;
while(j<=high){
if(j+<=high&&b[j]<b[j+]){
j=j+;
}
if(b[j]>b[i]){
swap(b[j],b[i]);
i=j;
j=i*;
}
else break;
}
}
int main()
{
scanf("%d",&n);
a.resize(n+);
b.resize(n+);
for(int i=;i<=n;i++) scanf("%d",&a[i]);
for(int i=;i<=n;i++) scanf("%d",&b[i]);
int flag=;
while(flag<=n&&b[flag]>=b[flag-]) flag++;
int index=flag;
while(flag<=n&&a[flag]==b[flag]) flag++;
if(flag==n+){
printf("Insertion Sort\n");
sort(b.begin()+,b.begin()++index);
for(int i=;i<=n;i++){
if(i!=) printf(" ");
printf("%d",b[i]);
}
}
else{
printf("Heap Sort\n");
int f=n;
while(f>&&b[f-]<=b[f]){
f--;
} swap(b[],b[f]);
downAdjust(,f-);
for(int i=;i<=n;i++){
if(i!=) printf(" ");
printf("%d",b[i]);
}
}
return ;
}
1098 Insertion or Heap Sort (25 分)(堆)的更多相关文章
- 【PAT甲级】1098 Insertion or Heap Sort (25 分)
题意: 输入一个正整数N(<=100),接着输入两行N个数,表示原数组和经过一定次数排序后的数组.判断是经过插入排序还是堆排序并输出再次经过该排序后的数组(数据保证答案唯一). AAAAAcce ...
- 1098 Insertion or Heap Sort (25分)
According to Wikipedia: Insertion sort iterates, consuming one input element each repetition, and gr ...
- pat 甲级 1098. Insertion or Heap Sort (25)
1098. Insertion or Heap Sort (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...
- PTA 09-排序3 Insertion or Heap Sort (25分)
题目地址 https://pta.patest.cn/pta/test/16/exam/4/question/676 5-14 Insertion or Heap Sort (25分) Accor ...
- PAT (Advanced Level) Practise - 1098. Insertion or Heap Sort (25)
http://www.patest.cn/contests/pat-a-practise/1098 According to Wikipedia: Insertion sort iterates, c ...
- PAT (Advanced Level) 1098. Insertion or Heap Sort (25)
简单题.判断一下是插排还是堆排. #include<cstdio> #include<cstring> #include<cmath> #include<ve ...
- PAT Advanced 1098 Insertion or Heap Sort (25) [heap sort(堆排序)]
题目 According to Wikipedia: Insertion sort iterates, consuming one input element each repetition, and ...
- 1098. Insertion or Heap Sort (25)
According to Wikipedia: Insertion sort iterates, consuming one input element each repetition, and gr ...
- PAT甲题题解1098. Insertion or Heap Sort (25)-(插入排序和堆排序)
题目就是给两个序列,第一个是排序前的,第二个是排序中的,判断它是采用插入排序还是堆排序,并且输出下一次操作后的序列. 插入排序的特点就是,前面是从小到大排列的,后面就与原序列相同. 堆排序的特点就是, ...
- 09-排序3 Insertion or Heap Sort (25 分)
According to Wikipedia: Insertion sort iterates, consuming one input element each repetition, and gr ...
随机推荐
- HDU 1155 Bungee Jumping(物理题,动能公式,弹性势能公式,重力势能公式)
传送门: Bungee Jumping Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- c语言描述的顺序表实现
//顺序表的实现:(分配一段连续地址给顺序表,像数组一样去操作) #include<stdio.h> #include<stdlib.h> #define OK 1 #defi ...
- o'Reill的SVG精髓(第二版)学习笔记——第九章
第九章:文本 9.1 字符:在XML文档中,字符是指带有一个数字值的一个或多个字节,数字只与Unicode标准对应. 符号:符号(glyph)是指字符的视觉呈现.每个字符都可以用很多不同的符号来呈现. ...
- Oracle listener.log 清理
在oracle中,如果不对监听日志文件进行截断(定期清理),那么监听日志文件会变得越来越大,由于一些老旧的OS不支持2GB以上的文件,故当listener.log文件超过2GB时,会出现无法处理新的连 ...
- 【SQL】Oracle和Mysql的分页、重复数据查询(limit、rownum、rowid)
上周三面试题有两道涉及Oracle的分页查询,没有意外地凉了,现在总结一下. · Mysql mysql的分页可以直接使用关键字limit,句子写起来比较方便. 语法: ① limit m,n -- ...
- sqlServer2014安装说明(windows7 64位)
SqlServer2014安装说明(windows7 64位) 地址:https://www.microsoft.com/zh-cn/download/details.aspx?id=42299 1, ...
- 将hexo放到github仓库上
完成了hexo的安装后, 我们只能在本地访问. 因此我们将它放到github上, 方便我们随时随地的用网址访问. 在Blog文件夹目录下输入: cnpm install --save hexo-dep ...
- 洛谷P3804 【模板】后缀自动机
题目描述 给定一个只包含小写字母的字符串 SS , 请你求出 SS 的所有出现次数不为 11 的子串的出现次数乘上该子串长度的最大值. 输入输出格式 输入格式: 一行一个仅包含小写字母的字符串 SS ...
- webpack 之 webpack-dev-server自动刷新
watch 首先介绍watch选项,参考这里.可实现相关源文件改变后自动更新bundle.js文件的功能.在配置文件中添加 watch:true 或执行 webpack -w,即可开启watch功能: ...
- jquery添加html代码的几种方法
经常用jq来DOM添加html代码 就总结了jq里面最常用的动态添加html代码的方法 append在元素内部的尾部加上元素 prepend在元素内部的前部加上元素 after在元素外部的尾部加上元素 ...