题意:

输入一个正整数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. java.lang.IndexOutOfBoundsException: Remember that ordinal parameters are 1-based!

    问题描述 java.lang.IndexOutOfBoundsException: Remember that ordinal parameters are 1-based! 红色部分报错 for ( ...

  2. 这是一篇通过open live writer发布的博文

    这两天零零总总的尝试了两三款写博客的软件,总感觉不怎么上手,最后还是使用博客园官方推荐的工具写博吧,简单方便,目前的功能基本都有,尤其是粘贴图片特别方便,回想之前的几篇博文,真是一种煎熬哈哈(对于我这 ...

  3. goahead web 服务器

    https://blog.csdn.net/xieyihua1994/article/details/74002413

  4. SARS病毒

    每一道题目皆是一处美丽的风景: 何为科技的力量和程序的思维哦,在这暑假的编程之路上,我要好好地体验一番来嘞! 数学规律是:f(n)=2^(n-1)+4^(n-1).     //递推分析可得!具体过程 ...

  5. idea配置checkstyle/findbugs/pmd插件

    前提条件:工程已导入idea 一,Findbugs/PMD/CheckStyles插件安装 打开settings的plugins,点击查找FindBugs-IDEA/PMDPlugin/CheckSt ...

  6. dbGet (二)

    dbGet是由它基本的语法加上各种object的attribute的组合构成的.大家在熟悉基本语法之后,就应该去学习各个object的attribute了.说实话,这很难,因为attribute很多, ...

  7. 【转载】SpringMVC框架介绍

    转自:http://com-xpp.iteye.com/blog/1604183 SpringMVC框架图   SpringMVC接口解释   DispatcherServlet接口: Spring提 ...

  8. liunx详解-2

    linux安装与配置 安装配置 虚拟机配置1G内存,1核CPU,50G硬盘,网络地址转换(NAT,主机作为路由构建内网) 镜像文件:http://mirror.nsc.liu.se/centos-st ...

  9. CTF_论剑场 头像

    首先打开链接发现这个链接是一个头像 然后下载这个头像 通过hxd分析一下 在编辑中查找 flag 然后发现flag是一个用base64 加密的一串文字 然后我们将这串文字 解密 然后再通过md5 32 ...

  10. 关于mybatis中sql映射文件模糊查询的使用

    1.从前台传递一个String类型的参数到后台进行查询,如果牵涉到模糊查询会报错,应该把参数封装到对象中再进行传递然后进行模糊查询 2.一个查询框,多个查询条件 <if test="c ...