题意:

输入一个正整数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. energy/heating data source

    HeatManDataLake 1. schema: hfors tables ambient_temperature_emd record the ambient temperature hourl ...

  2. ORA-00928: missing SELECT keyword

    问题描述 ORA-00928: missing SELECT keyword 问题原因 未写表名

  3. Linux源码编译安装php7.3

    ---恢复内容开始--- ps:一切从简 一.安装所需环境 yum -y install libxml2 libxml2-devel openssl openssl-devel curl-devel ...

  4. 剑指offer 面试题. 剪绳子

    题目描述 给你一根长度为n的绳子,请把绳子剪成整数长的m段(m.n都是整数,n>1并且m>1),每段绳子的长度记为k[0],k[1],...,k[m].请问k[0]xk[1]x...xk[ ...

  5. OpenCV图像载入、显示和输出到文件以及滑块的使用

    图像载入 imread()函数 Mat imread(const string& filename, int flags = 1); 第一个参数为文件名 第二个参数为载入标识 flags &g ...

  6. [ASP.NET]Web网站与Web应用程序区别

    [ASP.NET]Web网站与Web应用程序区别   本文链接:https://blog.csdn.net/a954553391/article/details/86403521 前言:在项目开发中, ...

  7. AcWing 154. 滑动窗口

    https://www.acwing.com/problem/content/156/ #include <iostream> using namespace std; ; int a[N ...

  8. PHP中spl_autoload_register()函数用法实例详解

    本文实例分析了PHP中spl_autoload_register()函数用法.分享给大家供大家参考,具体如下: 在了解这个函数之前先来看另一个函数:__autoload. 一.__autoload 这 ...

  9. Oracle的表空间、用户和模式

    Oracle 的 表空间(Tablespace).用户(User).模式(Schema)   前面有整理了一篇 Oracle 数据库(database) 与 实例(instance) 的概念及关系整理 ...

  10. C#中通过SendARP读取MAC地址

    C#中通过SendARP读取MAC地址: using System.Runtime.InteropServices; publicstaticstring GetMacBySendARP(string ...