PAT (Advanced Level) 1089. Insert or Merge (25)
简单题。模拟一下即可。
#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)的更多相关文章
- PAT甲级:1089 Insert or Merge (25分)
PAT甲级:1089 Insert or Merge (25分) 题干 According to Wikipedia: Insertion sort iterates, consuming one i ...
- 【PAT甲级】1089 Insert or Merge (25 分)(插入排序和归并排序)
题意: 输入一个正整数N(<=100),接着输入两行N个整数,第一行表示初始序列,第二行表示经过一定程度的排序后的序列.输出这个序列是由插入排序或者归并排序得到的,并且下一行输出经过再一次排序操 ...
- PAT Advanced 1089 Insert or Merge (25) [two pointers]
题目 According to Wikipedia: Insertion sort iterates, consuming one input element each repetition, and ...
- PAT 1089. Insert or Merge (25)
According to Wikipedia: Insertion sort iterates, consuming one input element each repetition, and gr ...
- 1089. Insert or Merge (25)
题目如下: According to Wikipedia: Insertion sort iterates, consuming one input element each repetition, ...
- 1089. Insert or Merge (25)-判断插入排序还是归并排序
判断插入排序很好判断,不是的话那就是归并排序了. 由于归并排序区间是2.4.8开始递增的,所以要判断给出的归并排序执行到哪一步,就要k从2开始枚举. 然后再对每个子区间进行一下sort即可. #inc ...
- 1089 Insert or Merge (25 分)
According to Wikipedia: Insertion sort iterates, consuming one input element each repetition, and gr ...
- 1089 Insert or Merge (25分)
According to Wikipedia: Insertion sort iterates, consuming one input element each repetition, and gr ...
- PAT (Advanced Level) 1113. Integer Set Partition (25)
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...
随机推荐
- Codeforces Round #275 (Div. 2)-A. Counterexample
http://codeforces.com/contest/483/problem/A A. Counterexample time limit per test 1 second memory li ...
- 官方webupload上传多个文件或者图片的方法
文件上传 页面代码: <!--引入CSS--> <link rel="stylesheet" type="text/css" href=&qu ...
- 初识 Hibernate
Hibernate 框架 1.1 什么是框架? 框架是一个提供了可重用的公共结构半成品. 2.1 关于Hibernate Hibernate是数据持久层的一个轻量级框架.数据持久层的框架有很多 ...
- java常用流处理工具StreamTool 常见的InputStream流转字符串, 转字节数组等等
ava 常用流处理工具 StreamTool ,常见的InputStream 流转字符串, 转字节数组等等 **应用场景: ** 1. 文件上传 2. js / css / img 等文件读取输出. ...
- java在线聊天项目 实现基本聊天功能后补充的其他功能详细需求分析 及所需要掌握的Java知识基础 SWT的激活方法,swt开发包下载,及破解激活码
补充聊天项目功能,做如下需求分析: 梳理项目开发所需的必要Java知识基础 GUI将使用更快速的swt实现 SWT(Standard Widget Toolkit) Standard Widget T ...
- javascript 写一个随机范围整数的思路
const {random} = Math; //返回 [min,max] 的随机值 //[0,1) * (max - min + 1) => [0,max-min+1) //[0,max-mi ...
- html中注释的问题
在修改jsp页面的时候遇到了一个有点难懂的注释,mark一下 <script> <!-- alert("js code"); //--> </scri ...
- break、continue、exit、return的区别和对比
break.continue.exit.return的区别和对比 一:说明 break.continue在条件循环语句及循环语句(for.while.if等)中用于控制程序的走向:而exit则用于种植 ...
- RN踩坑
使用夜神 使用夜神作为模拟器,这个模拟器启动就会监听62001端口. 开发工具与模拟器的通信都是通过adb.夜神模拟器的安装目录/bin下有一个adb.exe,android sdk tools下也有 ...
- python计算机基础(一)
什么是编程语言? 跟计算机交流的语言 什么是编程? 编程就是写代码,让计算机能够听懂的语言 为什么要编程? 让计算机为我们做事,取代人 计算机5大组成分别有什么作用? CPU:控制,判断,配作用,内存 ...