1089 Insert or Merge (25 分)

According to Wikipedia:

Insertion sort iterates, consuming one input element each repetition, and growing a sorted output list. Each iteration, insertion sort removes one element from the input data, finds the location it belongs within the sorted list, and inserts it there. It repeats until no input elements remain.

Merge sort works as follows: Divide the unsorted list into N sublists, each containing 1 element (a list of 1 element is considered sorted). Then repeatedly merge two adjacent sublists to produce new sorted sublists until there is only 1 sublist remaining.

Now given the initial sequence of integers, together with a sequence which is a result of several iterations of some sorting method, can you tell which sorting method we are using?

Input Specification:

Each input file contains one test case. For each case, the first line gives a positive integer N (≤100). Then in the next line, N integers are given as the initial sequence. The last line contains the partially sorted sequence of the N numbers. It is assumed that the target sequence is always ascending. All the numbers in a line are separated by a space.

Output Specification:

For each test case, print in the first line either "Insertion Sort" or "Merge Sort" to indicate the method used to obtain the partial result. Then run this method for one more iteration and output in the second line the resuling sequence. It is guaranteed that the answer is unique for each test case. All the numbers in a line must be separated by a space, and there must be no extra space at the end of the line.

Sample Input 1:

10
3 1 2 8 7 5 9 4 6 0
1 2 3 7 8 5 9 4 6 0

Sample Output 1:

Insertion Sort
1 2 3 5 7 8 9 4 6 0

Sample Input 2:

10
3 1 2 8 7 5 9 4 0 6
1 3 2 8 5 7 4 9 0 6

Sample Output 2:

Merge Sort
1 2 3 8 4 5 7 9 0 6

题目大意:给出一个序列判断是插入排序的过程还是归并排序的过程。

#include <iostream>
#include <algorithm>
#include <vector>
#include<cstdio>
using namespace std; int or[],now[];
int main()
{
int n;
cin>>n;
for(int i=;i<n;i++){
cin>>or[i];
}
for(int i=;i<n;i++){
cin>>now[i];
}
insertion();//我的天,我感觉好麻烦,我感觉好麻烦,我写不下去了。
//直接插入排序
for(int i=;i<n;i++)//直接插入排序是在原来的基础上,还是需要放到一个新的数组里?
//不知道参数该怎么传。
return ;
}

//这是我写的,实在是写不下去了。不会啊,下面是柳神的解答:

//怎么可以这么厉害,佩服!

PAT 1089 Insert or Merge[难]的更多相关文章

  1. PAT 1089. Insert or Merge (25)

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

  2. PAT 1089. Insert or Merge

    Insertion sort iterates, consuming one input element each repetition, and growing a sorted output li ...

  3. PAT甲级1089. Insert or Merge

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

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

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

  5. PAT (Advanced Level) 1089. Insert or Merge (25)

    简单题.模拟一下即可. #include<cstdio> #include<cstring> #include<cmath> #include<vector& ...

  6. 【PAT甲级】1089 Insert or Merge (25 分)(插入排序和归并排序)

    题意: 输入一个正整数N(<=100),接着输入两行N个整数,第一行表示初始序列,第二行表示经过一定程度的排序后的序列.输出这个序列是由插入排序或者归并排序得到的,并且下一行输出经过再一次排序操 ...

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

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

  8. 1089 Insert or Merge(25 分)

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

  9. 1089. Insert or Merge (25)

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

随机推荐

  1. 工具类之Mutex

    Mutex在Android4.4的源代码包的./system/core/include/utils/Mutex.h中定义并且实现. 我们先复习一下Mutex在Linux中功能: Mutex出生的意义就 ...

  2. php -- PDO异常处理

    异常处理: PHP:默认为直接报错 MYSQL:默认为静默模式,错就错,不报错 PDO:默认为静默模式,错就错,不报错 以前,当PHP碰到错误的时候,会直接报错,错误处理会变得相当麻烦.后来,当错误发 ...

  3. QTreeWidget 获取被双击的子项的层次路径

    from PyQt5.QtWidgets import (QApplication, QWidget, QHBoxLayout, QTreeWidget, QTreeWidgetItem, QGrou ...

  4. erlang-sunface的博客地址

    erlang-sunface的博客地址: http://blog.csdn.net/abv123456789/article/category/2206185

  5. ios开发之 -- Swap file ".Podfile.swp" already exists!

  6. m2014_c:C 工具库1:list

    转自:http://www.cnblogs.com/sniperHW/archive/2012/04/02/2429607.html 近来考虑将项目基础框架的开发语言从C++换成C,免不了要编写一大堆 ...

  7. IOS开发学习笔记039-autolayout 代码实现

    本文转载至 http://www.cnblogs.com/songliquan/p/4548206.html 1.代码实现比较复杂 代码实现Autolayout的步骤 利用NSLayoutConstr ...

  8. 使用javascript来访问本地文件夹

    常用的.net 的aspx文件由于运行在服务器端,并不具有访问用户本地文件夹的权限,导致类似于<a href="file:///d:/backup" > open fo ...

  9. std::condition_variable(二)

    #include <iostream> // std::cout #include <thread> // std::thread, std::this_thread::yie ...

  10. Eclipse启动Server报错:Could not publish to the server. java.lang.NullPointerException

    转载自:http://m.blog.csdn.net/article/details?id=49862243 错误信息: publishing to tomcat v8.0 server at loc ...