简单题。判断一下是插排还是堆排。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<algorithm>
using namespace std; const int maxn=;
int a[maxn],b[maxn],n; int main()
{
memset(b,-,sizeof b);
scanf("%d",&n);
for(int i=; i<=n; i++) scanf("%d",&a[i]);
for(int i=; i<=n; i++) scanf("%d",&b[i]); int flag=; int p=n+;
for(int i=; i<=n; i++)
if(b[i]<b[i-])
{
p=i;
break;
} for(int i=p; i<=n; i++)
{
if(a[i]==b[i]) continue;
else flag=;
} if(flag==)
{
printf("Insertion Sort\n");
if(p==n+) p=n;
sort(a+,a+p+);
for(int i=; i<=p; i++)
{
printf("%d",a[i]);
if(i<n) printf(" ");
else printf("\n");
}
for(int i=p+; i<=n; i++)
{
printf("%d",a[i]);
if(i<n) printf(" ");
else printf("\n");
}
}
else
{
printf("Heap Sort\n");
sort(a+,a++n);
for(int i=n; i>=; i--)
{
if(a[i]==b[i]) p=i;
else break;
} swap(b[],b[p-]); int i=;;
while()
{
if(*i<p-&&*i+<p-)
{
if(b[i]<max(b[*i],b[*i+]))
{ if(b[*i]>b[*i+])
{
swap(b[*i],b[i]);
i=*i;
}
else
{
swap(b[*i+],b[i]);
i=*i+;
}
}
else break;
}
else if(*i<p-)
{
if(b[i]<b[*i])
{
swap(b[*i],b[i]);
i=*i;
}
}
else break; }
for(int i=; i<=n; i++)
{
printf("%d",b[i]);
if(i<n) printf(" ");
else printf("\n");
}
} return ;
}

PAT (Advanced Level) 1098. Insertion or Heap Sort (25)的更多相关文章

  1. 【PAT甲级】1098 Insertion or Heap Sort (25 分)

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

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

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

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

  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. PAT甲题题解1098. Insertion or Heap Sort (25)-(插入排序和堆排序)

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

  6. 1098. Insertion or Heap Sort (25)

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

  7. 1098 Insertion or Heap Sort (25分)

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

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

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

  9. pat1098. Insertion or Heap Sort (25)

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

随机推荐

  1. java反射机制(2)

    首先,我们在开始前提出一个问题: 1.在运行时,对于一个java类,能否知道属性和方法:能否去调用它的任意方法? 答案是肯定的. 本节所有目录如下: 什么是JAVA的反射机制 JDK中提供的Refle ...

  2. TCP协议中的三次握手和四次挥手(图解)【转】

    建立TCP需要三次握手才能建立,而断开连接则需要四次握手.整个过程如下图所示: 先来看看如何建立连接的. [更新于2017.01.04 ]该部分内容配图有误,请大家见谅,正确的配图如下,错误配图也不删 ...

  3. 实现ie6下的居中

    代码如下所示,转自 http://w3help.org/zh-cn/causes/RT8003 对于 text-align 的讨论. <div style="width:200px; ...

  4. zendstudio 安装 手册

    安装 http://jingyan.baidu.com/article/b907e627b14fbb46e6891c65.html 选择baidu官方32bit安装 补丁破解网址 http://dwt ...

  5. C++内存申请容易产生的错误

    1.起因 前两天用python写了一款工具用来把excel文件转换成json文件,今天给他们用的时候发现在文本下看正常,但是在程序中使用就是会多出一些莫名其妙的字符. 2. 调查 原来主要是我写的工具 ...

  6. js导入的注意.txt

    如有两个外部js文件: jquery-1.8.2.min.js Jqery的系统文件 LYFArray.js 和个人的 ===============我要将两个js文件导入一个页面的方法:====== ...

  7. hdu_5705_Clock("巴卡斯杯" 中国大学生程序设计竞赛 - 女生专场)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5705 题意:给你一个时间和一个角度,问你下一个时针和分针形成给出的角度是什么时候 题解:我们可以将这个 ...

  8. CentOS ulimit

    Linux 文件系统设置 文件句柄数 ulimit -n 查看 echo "* - nofile 65536" >> /etc/security/limits.conf ...

  9. 给php代码添加规范的注释phpDocumentor

    给php代码添加规范的注释更多参考 http://phpdoc.org/docs/latest/index.html在phpdocumentor中,注释分为文档性注释和非文档性注释.所谓文档性注释,是 ...

  10. 开始制作国产的 scratch

    首先分析下API和数据格式: https://api.scratch.mit.edu/proxy/featured  GET   23.235.37.162:443 返回数据与对应栏目: commun ...