题意:

输入一个正整数N(<=100),接着输入两行N个整数,第一行表示初始序列,第二行表示经过一定程度的排序后的序列。输出这个序列是由插入排序或者归并排序得到的,并且下一行输出经过再一次排序操作所得到的序列。数据保证了不会有两种排序方式都可以得到的序列。

AAAAAccepted code:

 #define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int a[];
int b[];
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=n;i;--i)
if(a[i]!=b[i]){
pos=i;
break;
}
int flag=;
int loc=;
for(int i=;i<n;++i)
if(b[i]>b[i+]){
loc=i;
break;
}
for(int i=loc+;i<=n;++i)
if(a[i]!=b[i]){
flag=;
}
if(flag){
cout<<"Insertion Sort\n";
sort(a+,a++loc+);
for(int i=;i<=n;++i){
cout<<a[i];
if(i<n)
cout<<" ";
}
}
else{
cout<<"Merge Sort\n";
int t=;
while(){
int flag=;
for(int i=;i<=n;++i)
if(a[i]!=b[i]){
flag=;
break;
}
t*=;
for(int i=;i<=n/t;++i)
sort(a+(i-)*t+,a+i*t+);
sort(a+n/t*t+,a+n+);
if(!flag)
break;
}
for(int i=;i<=n;++i){
cout<<a[i];
if(i<n)
cout<<" ";
}
}
return ;
}

【PAT甲级】1089 Insert or Merge (25 分)(插入排序和归并排序)的更多相关文章

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

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

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

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

  3. PAT甲级1089. Insert or Merge

    PAT甲级1089. Insert or Merge 题意: 根据维基百科: 插入排序迭代,消耗一个输入元素每次重复,并增加排序的输出列表.每次迭代,插入排序从输入数据中删除一个元素,在排序列表中找到 ...

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

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

  5. 1089 Insert or Merge (25 分)

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

  6. 1089 Insert or Merge (25分)

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

  7. PTA 09-排序2 Insert or Merge (25分)

    题目地址 https://pta.patest.cn/pta/test/16/exam/4/question/675 5-13 Insert or Merge   (25分) According to ...

  8. PAT 甲级 1083 List Grades (25 分)

    1083 List Grades (25 分) Given a list of N student records with name, ID and grade. You are supposed ...

  9. PAT 甲级 1040 Longest Symmetric String (25 分)(字符串最长对称字串,遍历)

    1040 Longest Symmetric String (25 分)   Given a string, you are supposed to output the length of the ...

随机推荐

  1. K-NN graph

    tasks: 1. unsupervised knn https://scikit-learn.org/stable/modules/neighbors.html#unsupervised-neigh ...

  2. Python记

    在企业应用领域,Java或C#都是不错的选择.

  3. Git的基本使用 -- 分支管理

    查看分支 git branch 前面带 * 的为当前所在分支 创建分支 git branch 分支名 切换分支 git checkout 分支名 创建并切换到此分支 git checkout -b 分 ...

  4. JDK的卸载和安装

    Java入门 Java最大优势:基于JVM,跨平台 Java的几个版本 JavaSE:标准版,占领桌面,桌面程序,控制台开发等. JavaME:嵌入式开发,占领手机,手机,小家电等.(几乎死掉了) J ...

  5. SpringMVC-时间类型转换

    在上一篇SpringMVC的提交表单中,我们使用的日期为String型,可以将日期转换为Date型,然后使用initBinder函数进行显示,具体代码如下: (1)首先更改User.java的birt ...

  6. night of 2019.8.14

    饭后一个小时,坐下来看了一会书,是原来的同事推荐的. 最近一段时间,心一点一点平静.能平下心来去做一些事.偶尔也常常对着窗户发呆,想一些人生感悟.想到一些感悟时,常常感到没有人可以说说心里话. 丰子恺 ...

  7. 如何更改已经pushed的commit的注释信息(How to change the pushed commit message)

    1, 修改最后一次注释(Modify the last comment message) git commit -amend 2,修改之前的注释 1)输入: git rebase -i HEAD~3 ...

  8. 5G手机来了,但这些问题让其短期内难以成为“香饽饽”

    在5G手机喊了太长时间后,其终于在近日不断亮相. 此前据中国质量认证中心官网显示,共有8款5G手机获得3C认证--华为4款,一加.中兴.OPPO和vivo各有一款.随着首批5G手机通过3C认证,意味着 ...

  9. [Note]Splay学习笔记

    开个坑记录一下学习Splay的历程. Code 感谢rqy巨佬的代码,让我意识到了Splay可以有多短,以及我之前的Splay有多么的丑... int fa[N], ch[N][2], rev[N], ...

  10. JavaWeb项目忘记添加依赖

    有的时候我们建项目的时候忘记添加项目的依赖了,这里示范一个提示错误,就是 The superclass "javax.servlet.http.HttpServlet" was n ...