PAT 1089 Insert or Merge[难]
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[难]的更多相关文章
- PAT 1089. Insert or Merge (25)
According to Wikipedia: Insertion sort iterates, consuming one input element each repetition, and gr ...
- PAT 1089. Insert or Merge
Insertion sort iterates, consuming one input element each repetition, and growing a sorted output li ...
- PAT甲级1089. Insert or Merge
PAT甲级1089. Insert or Merge 题意: 根据维基百科: 插入排序迭代,消耗一个输入元素每次重复,并增加排序的输出列表.每次迭代,插入排序从输入数据中删除一个元素,在排序列表中找到 ...
- PAT甲级:1089 Insert or Merge (25分)
PAT甲级:1089 Insert or Merge (25分) 题干 According to Wikipedia: Insertion sort iterates, consuming one i ...
- PAT (Advanced Level) 1089. Insert or Merge (25)
简单题.模拟一下即可. #include<cstdio> #include<cstring> #include<cmath> #include<vector& ...
- 【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 ...
- 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, ...
随机推荐
- js实现EasyUI-datagrid前台分页
//实现假分页 function myLoader(param, success, error) { var that = $(this); var opts = that.datagrid(&quo ...
- C++ 类的继承二(赋值兼容性原则)
//赋值兼容性原则 #include<iostream> using namespace std; class PointA{ public: PointA(){ x = ; y = ; ...
- 敏捷软件开发实践-Sprint Retrospective Meeting(转)
介绍: 在敏捷开发模式中,Sprint Retrospective Meeting 也是一个必不可少的环节,它通常发生在每个Sprint的结尾,其主要作用是对于当前的迭代周期做一个阶段性的总结,包括好 ...
- 【UVa】Wavio Sequence(dp)
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- 返回flag
//修改前namespace CleanCSharp.Errors.Dirty { public class SomeClass { public int DoSomeProcess(int? id) ...
- java泛型之泛型边界
http://blog.csdn.net/renwuqiangg/article/details/51296621
- 数据库布尔型状态字段互斥性的SQL更新操作
一个配置表或者一个存储了多条状态的表,需要在某个状态中做切换,而当前是否启用状态标记是用0和1来标识的.这个时候通常 1表示正在使用中,0表示不在使用中.通常有些业务会做一些配置的状态切换,就会出现要 ...
- 第三篇:C++ 中的几种初始化
前言 阅读C++教材时,想必你听过复制初始化,直接初始化,值初始化这三个概念吧.笔者本人常将其混淆,遂在此记录下它们的具体含义以便日后查阅. 复制初始化( copy-initialization ) ...
- iOS 文件和数据管理 (可能会删除本地文件储存)
转自:http://www.apple.com.cn/developer/iphone/library/documentation/iPhone/Conceptual/iPhoneOSProgramm ...
- PL/SQL Developer使用技巧、快捷键(转载)
1.类SQL PLUS窗口:File->New->Command Window,这个类似于oracle的客户端工具sql plus,但比它好用多了. 2.设置关键字自动大写:Tools-& ...