题意:

输入一个正整数N(<=100),接着输入两行N个数,表示原数组和经过一定次数排序后的数组。判断是经过插入排序还是堆排序并输出再次经过该排序后的数组(数据保证答案唯一)。

AAAAAccepted code:

 #define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int a[],b[];
int c[][];
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin>>n;
for(int i=;i<=n;++i)
cin>>a[i];
for(int i=;i<=n;++i)
cin>>b[i];
int pos=;
for(int i=;i<n;++i)
if(b[i]>b[i+]){
pos=i;
break;
}
int pos2=;
for(int i=pos+;i<=n;++i)
if(a[i]!=b[i]){
pos2=i;
break;
}
if(!pos2){
cout<<"Insertion Sort\n";
int flag=,mn=b[pos+];
int ppos=;
for(int i=;i<=n;++i)
if(b[i]>mn){
ppos=i;
break;
}
for(int i=pos+;i>ppos;--i)
b[i]=b[i-];
b[ppos]=mn;
for(int i=;i<=n;++i){
cout<<b[i];
if(i<n)
cout<<" ";
}
}
else{
cout<<"Heap Sort\n";
int ppos=;
sort(a+,a++n);
for(int i=n;i;--i)
if(b[i]!=a[i]){
ppos=i;
break;
}
int mx=,flag=;
for(int i=;i<=ppos;++i)
if(b[i]>mx){
mx=b[i];
flag=i;
}
swap(b[flag],b[ppos]);
int s=;
while(s<ppos){
if(b[s*]>b[s]&&b[s*+]>b[s]&&ppos>s*+){
if(b[s*]>b[s*+]){
swap(b[s],b[s*]);
s=s*;
}
else{
swap(b[s],b[s*+]);
s=s*+;
}
}
else if(b[s*+]>b[s]&&ppos>s*+){
swap(b[s],b[s*+]);
s=s*+;
}
else if(b[s*]>b[s]&&ppos>s*){
swap(b[s],b[s*]);
s=s*;
}
if(s*>=ppos)
break;
}
for(int i=;i<=n;++i){
cout<<b[i];
if(i<n)
cout<<" ";
}
}
return ;
}

【PAT甲级】1098 Insertion or Heap Sort (25 分)的更多相关文章

  1. pat 甲级 1098. Insertion or Heap Sort (25)

    1098. Insertion or Heap Sort (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...

  2. PAT甲级1098. Insertion or Heap Sort

    PAT甲级1098. Insertion or Heap Sort 题意: 根据维基百科: 插入排序迭代,消耗一个输入元素每次重复,并增加排序的输出列表.在每次迭代中,插入排序从输入数据中删除一个元素 ...

  3. PAT甲级——1098 Insertion or Heap Sort (插入排序、堆排序)

    本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/90941941 1098 Insertion or Heap So ...

  4. PAT Advanced 1098 Insertion or Heap Sort (25) [heap sort(堆排序)]

    题目 According to Wikipedia: Insertion sort iterates, consuming one input element each repetition, and ...

  5. 1098 Insertion or Heap Sort (25分)

    According to Wikipedia: Insertion sort iterates, consuming one input element each repetition, and gr ...

  6. 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 ...

  7. 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 ...

  8. PAT (Advanced Level) 1098. Insertion or Heap Sort (25)

    简单题.判断一下是插排还是堆排. #include<cstdio> #include<cstring> #include<cmath> #include<ve ...

  9. PAT甲题题解1098. Insertion or Heap Sort (25)-(插入排序和堆排序)

    题目就是给两个序列,第一个是排序前的,第二个是排序中的,判断它是采用插入排序还是堆排序,并且输出下一次操作后的序列. 插入排序的特点就是,前面是从小到大排列的,后面就与原序列相同. 堆排序的特点就是, ...

随机推荐

  1. [Codechef - ADITREE] Adi and the Tree - 树链剖分,线段树

    [Codechef - ADITREE] Adi and the Tree Description 树上每个节点有一个灯泡,开始所有灯泡都是熄灭的.每次操作给定两个数 \(a,b\) ,将 \(a,b ...

  2. json_encode中文不转义问题

    //php5.3之后才有这个参数,这样存入数据库中的中文json数据就不会转义,也能被正确解析1JSON_UNESCAPED_UNICODE(中文不转为unicode ,对应的数字 256) JSON ...

  3. 基于.NET Core winform的录音、字幕软件HTWCore的技术总结

    HTWCore是一款基于.NET Core的winform客户端程序,可以用来处理各种会议,记录,讲座,讲课等等来源的音视频,运用语音识别.视频内容提取等技术整理成word文档.项目中运用了以下技术: ...

  4. IDEA与Tomcat相关配置

    idea会为每一个Tomcat部署的项目,独立建一份配置文件. 配置文件所在位置 怎么部署的(查看虚拟目录)使用的第三种部署方式 部署项目存放的路径 项目目录和Tomcat部署目录 Tomcat真正访 ...

  5. HBase 中 Memstore-Local Allocation Buffer

    在0.90 版本后的 HBase,引入了一个高级机制用于缓解堆内存碎片的问题.此内存碎片问题的产生的主要原因是由于 memstore 上的扰动(频繁的分配与释放内存空间)导致.对应解决此问题的机制为M ...

  6. vue 文件插件 Vetur 设置说明官网

    vue 文件插件 Vetur 设置说明官网 https://vuejs.github.io/vetur/formatting.html#settings

  7. Ultra-Thin LED Downlight Selection: 6 Things

    LED Decorative Light Manufacturer    description: ultra-thin LED downlight features can maintain the ...

  8. AC3 IMDCT

    AC3 encoder 在进行MDCT时,使用两种长度的block. 512 samples的block用于输入信号频谱是stationary,或者在时间上变化缓慢.在fs 为48k时,使用512 s ...

  9. Java下载文件时文件名中的中文变成下划线,其他正常

    将 utf-8 转换成 ISO8859-1 编码 response.addHeader("Content-Disposition", "attachment;filena ...

  10. n阶高精度乘法,(求高阶阶乘)

    先来复习一下小学数学 : 大家还记不记得小学算多位数的乘法是怎么算的? 卖个关子,大家一定要好好想想! 好了,别管到底还能不能想起来我们都要一块复习一下: 我们借助一下源自百度的图片 来复习下 相信大 ...