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 2005 第几天?(闰年判断)
传送门: acm.hdu.edu.cn/showproblem.php?pid=2005 第几天? Time Limit: 2000/1000 MS (Java/Others) Memory L ...
- 使用Spring框架能带来那些好处?
1.Dependency Injection(DI)方法使得构造器和JavaBean properties文件中的依赖关系一目了然. 2.与EJB容器相比较,Ioc容器更加趋向于轻量级.这样一来Ioc ...
- [SDOI2008]仪仗队(欧拉筛裸题)
题目描述 作为体育委员,C君负责这次运动会仪仗队的训练.仪仗队是由学生组成的N * N的方阵,为了保证队伍在行进中整齐划一,C君会跟在仪仗队的左后方,根据其视线所及的学生人数来判断队伍是否整齐(如右图 ...
- CSS实现表单
效果图如下: HTML代码如下: <!DOCTYPE html> <html lang="en"> <head> <meta charse ...
- 关于mysql8.0.11版本在win10安装
新的mysql版本没有.exe文件一键安装,网上找了教程,自己搞了下 首先是在菜鸟教程 http://www.runoob.com/mysql/mysql-install.html 根据它的提示下载w ...
- DevOps - 配置管理 - Ansible
http://www.zsythink.net/archives/category/运维相关/ansible/
- 新知识 HtMl 5
快要毕业了,即将走向实习岗位,但是这日子过的太无聊了,昨天逃课回宿舍打开电脑想看电影但是没什么好看的,于是上床睡觉了,越躺越无聊,然后爬了起来到学习图书馆找了本HTML5的课本,学习了起来(我感觉ht ...
- python 方法解析顺序 mro
一.概要: mor(Method Resolution Order),即方法解析顺序,是python中用于处理二义性问题的算法 二义性: 1.两个基类,A和B都定义了f()方法,c继承A和B那么C调用 ...
- php-7.2.3源代码和php-5.6.26源代码摘录,对比 “汇编php文件”和“执行opcode代码”
php-7.2.3 在“汇编php文件”和“执行opcode代码”上做了大量改变php-5.6.26 没见到支持抽象语法树的相关代码,php-7.2.3 见到支持抽象语法树的相关代码php-5.6.2 ...
- z-blog博客组插件openSug.js百度搜索下拉框提示代码
z-blog安装openSug插件即可获得带有“搜索框提示”功能的搜索框,让z-blog搜索更便捷! https://www.opensug.org/.../opensug_z-blog_v1.0 ...