简单题。模拟一下即可。

#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. 科普NDIS封包过滤

    闲言:    这个月一直在学习NDIS驱动编程,杂七杂八的资料都看个遍了,做了点笔记,捋捋思路,发上来备忘.    Ps:只是小菜的一点学习笔记,没什么技术含量,不过版主如果觉得对大家稍微有点帮助的话 ...

  2. makeObjectsPerformSelector用法

    亲测 makeObjectsPerformSelector 的用法. - (void)makeObjectsPerformSelector:(SEL)aSelector NS_SWIFT_UNAVAI ...

  3. <MySQL>入门一 查询 DQL

    1. 数据库表 1.1 员工表 Create Table CREATE TABLE `employees` ( `employee_id` ) NOT NULL AUTO_INCREMENT, `fi ...

  4. Python自动化测试框架——数据驱动(从文件中读取)

    学过编程的伙伴们都知道,数据不仅可以从代码中读取,还可以从文件中读取. 今天小编就简要的介绍一下从文件中读取数据,并应用到自动化测试中方法. 先来展示下接下来将要用到的文件在项目中的结构 从txt文件 ...

  5. Linux-ngnix服务(二)

    Nginx介绍 特性: 模块化设计,较好的扩展性 高可靠性 支持热部署:不停机更新配置文件,升级版本,更换日志文件 低内存消耗:10000个keep-alive连接模式下的非活动连接,仅需2.5M内存 ...

  6. 收集自网络上有关Kali的各种源

    更新源总结 #更新源 gedit /etc/apt/sources.list   #中科大kali源   deb http://mirrors.ustc.edu.cn/kali kali-rollin ...

  7. Flask 系列之 构建 Swagger UI 风格的 WebAPI

    说明 操作系统:Windows 10 Python 版本:3.7x 虚拟环境管理器:virtualenv 代码编辑器:VS Code 实验 环境初始化 # 创建项目目录 mkdir helloworl ...

  8. django(django项目创建,数据库迁移)

    Django项目的创建与介绍 安装:pip3 install django==1.11 查看版本号:django-admin --version 新建项目: 1.切到目标目录 2.django-adm ...

  9. S3C6410串口平台设备注册流程分析

    1.mdesc->map_io() start_kernel -->setup_arch(&command_line); -->paging_init(mdesc); --& ...

  10. Linux poll机制

    1.用户空间调用(参考 poll(2) - Linux man page) int poll(struct pollfd *fds, nfds_t nfds, int timeout); it wai ...