题意:

输入一个正整数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. adb 连接手机

    adb kill-server adb start-server 可能会遇到问题华为手机: 有应用遮挡了权限请求界面,设置应用无法验证你的回应 系统导航关闭悬浮球 然后重启adb  server ad ...

  2. Java连载77-Integer常用方法、Integer、int、String三者相互转化、自动装箱、自动拆箱

    一.关于Integer中常用的方法 package com.bjpowernode.java_learning; ​ public class D77_1_ { public static void ...

  3. zookeeper入门之介绍与安装

    一:zookeeper是什么 What is ZooKeeper? ZooKeeper is a centralized service for maintaining configuration i ...

  4. css的div动态水平垂直居中

      div动态水平垂直居中,思路如下: (1)先定位.如果相对于距离最近的父元素,用absolute:如果相对于body,用fixed. (2)然后,top和left都设为50%. (3)要居中的di ...

  5. js -- 日期时间格式化

    /** * js日期时间格式化 * @param date 时间读对象 * @param format 格式化字符串 例如:yyyy年MM月dd日 hh时mm分ss秒 * @returns {stri ...

  6. vmware Linux虚拟机挂载共享文件夹

    本文主要是记录vmware linux虚拟机如何挂载共享文件夹过程,以备不时之需. 设置允许共享文件夹 1. 启用共享文件夹 [VM]->[settings]->[Options]-> ...

  7. Flink流处理(五)- 状态与一致性模型

    状态(State)与一致性模型 接下来我们转向另一个在流处理中十分重要的点:状态(state).状态在数据处理中是无处不在的.为了产生一个结果,函数一般会聚合某个时间段内(或是一定数量的)events ...

  8. 题解【洛谷P2513/CJOJ1345】[HAOI2009]逆序对数列

    P1345 - [HAOI2009]逆序对数列 Description 对于一个数列{ai},如果有i<j且ai>aj,那么我们称ai与aj为一对逆序对数.若对于任意一个由1~n自然数组成 ...

  9. 每天进步一点点------Allegro使用脚本记录文件设置工作环境的颜色

    script脚本文件在Allegro PCB DESIGN中能完成很多参数设定,功能很强大.使用script脚本我们能够快速定制自己的Allegro workbench environment. 案例 ...

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

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