简单题。模拟一下即可。

#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()
{
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("Merge Sort\n"); int len=;
while()
{
int pp=;
while()
{
if(pp+len->n)
{
sort(a+pp,a+n+);
break;
}
else
{
sort(a+pp,a+pp+len);
pp=pp+len;
}
} int fail=;
for(int i=; i<=n; i++) if(a[i]!=b[i]) fail=; if(fail==)
{
len=len*;
int ppp=;
while()
{
if(ppp+len->n)
{
sort(a+ppp,a+n+);
break;
}
else
{
sort(a+ppp,a+ppp+len);
ppp=ppp+len;
}
}
for(int i=;i<=n;i++)
{
printf("%d",a[i]);
if(i<n) printf(" ");
else printf("\n");
}
break;
}
len=len*;
}
} return ;
}

PAT (Advanced Level) 1089. Insert or Merge (25)的更多相关文章

  1. PAT甲级:1089 Insert or Merge (25分)

    PAT甲级:1089 Insert or Merge (25分) 题干 According to Wikipedia: Insertion sort iterates, consuming one i ...

  2. 【PAT甲级】1089 Insert or Merge (25 分)(插入排序和归并排序)

    题意: 输入一个正整数N(<=100),接着输入两行N个整数,第一行表示初始序列,第二行表示经过一定程度的排序后的序列.输出这个序列是由插入排序或者归并排序得到的,并且下一行输出经过再一次排序操 ...

  3. PAT Advanced 1089 Insert or Merge (25) [two pointers]

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

  4. PAT 1089. Insert or Merge (25)

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

  5. 1089. Insert or Merge (25)

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

  6. 1089. Insert or Merge (25)-判断插入排序还是归并排序

    判断插入排序很好判断,不是的话那就是归并排序了. 由于归并排序区间是2.4.8开始递增的,所以要判断给出的归并排序执行到哪一步,就要k从2开始枚举. 然后再对每个子区间进行一下sort即可. #inc ...

  7. 1089 Insert or Merge (25 分)

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

  8. 1089 Insert or Merge (25分)

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

  9. PAT (Advanced Level) 1113. Integer Set Partition (25)

    简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...

随机推荐

  1. shell脚本,当用sed删除某一文件里面的内容时,并追加到同一个文件会出现问题。

    shell脚本,当用sed删除某一文件里面的内容时,并追加到同一个文件会出现问题.因为初始文件和写入文件是一个文件这是失败的.需要追加到另一个文件,然后再用mv进行操作.[root@localhost ...

  2. 17条 Swift 最佳实践规范

    本文由CocoaChina译者小袋子(博客)翻译自schwa的github主页原文作者:schwa 这是一篇 Swift 软件开发的最佳实践教程. 前言 这篇文章是我根据在 SwiftGraphics ...

  3. Taro:使用taro完成小程序开发

    前言:taro是一个可以很好实现一次开发,多端统一的框架,本文只介绍它小程序端开发的一些内容.小程序项目搭建gitup已经有很清楚的说明:https://github.com/NervJS/taro ...

  4. docker apache安装

    文章来源: 1.添加镜像 # docker pull httpd2. 2.创建httpd文件 # mkdir /data/httpd2. 3.启动apache # docker run -it -p ...

  5. (转) [C++]我再也不想在任何头文件中看到using namespace xxx这种句子了(译)

    原文的传送:I don’t want to see another “using namespace xxx;” in a header file ever again 转自  http://blog ...

  6. ios开发中关闭textview控件的虚拟键盘

    在ios开发中,textfield控件在点击的时候出现虚拟键盘,关掉虚拟键盘可以通过虚拟键盘中的done button和点击view中的任意地方来关闭虚拟键盘. 1.第一种方法是textfield控件 ...

  7. maven 打某一个模块的包

    mvn clean mvn clean install -pl benefit-microservice-gateway -am -Dmaven.test.skip=true

  8. 7,数据类型转换,set 集合,和深浅copy

    str转换成list  用split list转换成str  用join tuple转换成list tu1 = (1,2,3) li = list(tu1)(强转) tu2 = tuple(li)(强 ...

  9. selenium之定位以及切换frame

    总有人看不明白,以防万一,先在开头大写加粗说明一下: frameset不用切,frame需层层切! 很多人在用selenium定位页面元素的时候会遇到定位不到的问题,明明元素就在那儿,用firebug ...

  10. Leetcode 396.旋转函数

    旋转函数 给定一个长度为 n 的整数数组 A . 假设 Bk 是数组 A 顺时针旋转 k 个位置后的数组,我们定义 A 的"旋转函数" F 为: F(k) = 0 * Bk[0] ...