简单题。模拟一下即可。

#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. QT+常用控件_Line Edit

    #include "mainwindow.h" #include "ui_mainwindow.h" #include <QDebug> #incl ...

  2. Java多线程大合集

    1) 什么是线程? 线程是操作系统能够进行运算调度的最小单位,它被包含在进程之中,是进程中的实际运作单位.程序员可以通过它进行多处理器编程,你可以使用多线程对运算密集型任务提速.比如,如果一个线程完成 ...

  3. JS与IOS、安卓的交互

    最近做的项目中涉及到了与安卓和ios的交互问题,对于一个新手来说,多多少少会有点迷糊.在调用安卓和ios的callback回调时,很轻松的就调用成功了,而且,步骤也不那么繁琐.刚开始,只知道那样使用可 ...

  4. SQL 牛刀小试 1 —— 查询操作

    #创建数据库create database ST CHARACTER set utf8;#创建用户create user ST identified by '19980510';#授权用户操作该数据库 ...

  5. 【转】4w+1h 教你如何做用户画像

    记得14年开始做用户画像的时候,对于用户画像完全没有概念,以为是要画一幅幅图画,经过两年多的学习和理解,渐渐的总结出了一些方法和技巧,在这里就通过4个W英文字母开头和1个H英文字母开头的单词和大家分享 ...

  6. shell-code-5-函数

    # 函数必须在使用前定义 # 如果不写return,将以最后一条命令运行结果,作为返回值. return后跟数值n(0-255) myFistFunc(){ read a read b return ...

  7. (转)python之禅

    凡是用过 Python的人,基本上都知道在交互式解释器中输入 import this 就会显示 Tim Peters 的 The Zen of Python,但它那偈语般的语句有点令人费解,所以我想分 ...

  8. "javac不是内部或外部命令"的解决办法

    “javac不是内部或外部命令”,而此时的java环境是好用的: 1.先检查 JAVA_HOME  =   C:\Program Files\Java\jdk1.7.0_45 classpath   ...

  9. 关于在一台主机上安装2个不同版本的Oracle服务端

    一.安装Oracle12c 按正常安装方法安装即可! ORACLE_BASE=/u01/app ORACLE_HOME=/u01/app/oracle ORACLE_SID=a4orcl 二.安装Or ...

  10. java中传入一个数或字符串或数组进行反转

    //将一个数用递归反转--利用余数 public static void inverse(int n) { System.out.print(n % 10); if (n >= 10) inve ...