Insert or Merge(如何判断插入和合并排序)

PTA Insert or Merge 思路分析及代码解析 排序算法练习题 阅读详情

7-2 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 Nnumbers. 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

思路:用的是最笨的方法,纯模拟过程。一次插入排序的,两次插入排序的,去匹配到最合适的。

写了6个小时。。。这都是什么测试点。。。

 

07-排序2. Insert or Merge (25).zip http://blog.youkuaiyun.com/xkzju2010/article/details/46633425 立即下载

相关推荐

自动驾驶关键技术(一):时间敏感网络TSN

时间敏感网络TSN的基本概念、协议族介绍和开发流程。

3081

7-13 Insert or Merge (25 分)

https://www.nowcoder.com/pat/2/problem/267 吐槽:水题 #include #include char str[50]; int change(int sum,int x){ memset(str,0,sizeof(str)); int k = 0,ans = 0; do{ int tmp = sum % x;

姚军 475

深入解析组合逻辑环(combinational loop)的成因与解决方案

本文深入解析了数字电路设计中组合逻辑环(combinational loop)的成因与危害。通过边沿检测和中断轮询(round_robin)仲裁器等实例,揭示了代码如何意外形成环路,并对比了插入触发器、重构逻辑以及状态机思维三种核心解决方案,帮助硬件工程师从根本上避免这一常见设计陷阱,确保电路稳定可靠。

weixin_28278377的博客 315

09-排序2 Insert or Merge

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, f...

qq_29718605的博客 305

MicroCap声学仿真介绍(二)-创建声学仿真元件

声学库里包含孔、管、障板辐射器等器件,我们只需要按照仿真的需求,将声学库里的器件排列好,输入参数,用线连接起来即可。这里我们用D指代孔的直径,L指代孔的长度,N代表孔的数量。26.在弹出的界面中做如下设置:需要先在右面的选框里找到对应的项,然后右键Add Part,再之后就如下设置。3.在弹出的界面中,选择“Macro file(.mac)”,并点击右上角的“OK”下面就以声学仿真中常见的“孔”来做示例,跟大家一块演示一下宏程序的新建。10.在上图中“Value”中填入“R”,然后点击左边的“OK”按钮;

山无忧的博客 2203

规控面试常见问题

规划控制算法常见问题。

每天进步一点点。 984

天梯赛练习——7-17 Insert or Merge (25分)(归并+插入)

题目: 代码: #include <iostream> #include <algorithm> #include <cstring> #include <cstdio> using namespace std; const int MAXN = 105; int num[MAXN],tmp[MAXN],val[MAXN]; int n; bo...

Joker的博客 200

【MATLAB】嵌入式ADC/DAC控制工程

摘要:本文针对嵌入式ADC/DAC应用中存在的量化误差、采样噪声、输出漂移等问题,提出基于MATLAB的仿真优化方案。通过构建完整的ADC/DAC仿真模型,实现了采样建模、数字滤波、误差校准和闭环控制仿真。方案采用滑动平均滤波抑制ADC噪声,双校准参数补偿DAC固有误差,并将算法轻量化移植至STM32平台。实测表明,该方案使ADC采样波动从±25mV降至±5mV,DAC输出偏差从42mV降至18mV,显著提升了模拟量交互精度和系统稳定性。整套方案资源占用低,适配各类嵌入式高精度控制场景,具有较高的工程应用价

unber的博客 650

(c语言详解)09-排序2 Insert or Merge (详细解释)

首先肯定要将数组与输入的增量的序列作比较,如果相等说明就是这种排序,其次就是两种排序,第三就是main函数,比如在插入排序里做一下这样的手脚,他就在每趟排序的时候就会判断

执念斩长河 1502

C++软件调试与异常排查从入门到精通专栏介绍与文章汇总

根据近几年排查软件异常的实践与经验,系统地讲解了C++软件异常常见原因与常用排查方法,以图文并茂的方式给出具体的分析实例,带领大家逐步掌握C++软件异常排查的相关技术与要领。

dvlinker的技术专栏 23万+

*手把手教你学 Simulink——压缩机用永磁同步电机无位置传感器 I‑F 启动(Sensorless I/F Starting)控制仿真

dtdi^α​​zα​e^α​ω^θ^​=Ls​1​(−Rs​i^α​+usα​−zα​)=K⋅sign(i^α​−iα​)=zα​+Kpll​⋅(i^α​−iα​)同理 β=PLL(e^α​,e^β​)=∫ω^dt​。给定 Id​=Iset​, Iq​=f(θopen​)按设定 fstart​(t)Iq​=k⋅sin(θopen​)投影 → 恒幅 Is​=Id2​+Iq2​​。​ 将 Id​,Iq​→ Iα​,Iβ​→ SVPWM。Id​=Ialign​(弱对齐 → 防抖动)

amy_mhd的博客 39

Insert or Merge

本博客的代码的思想和图片参考:好大学慕课浙江大学陈越老师、何钦铭老师的《数据结构》 Insert or Merge 1 Question According to Wikipedia: Insertion sort iterates, consuming one input element each repetition, and growing a sorted ou...

dixiantong2202的博客 197

从零开始跑通3DGS教程:(五)3DGS训练

本文介绍了在Docker环境中训练3DGS(3D Gaussian Splatting)的方法,属于《从零开始跑通3DGS教程》系列文章的第五部分。主要内容包括:Docker环境准备(基于pytorch/pytorch:1.13.1-cuda11.6-cudnn8-runtime镜像)、容器内conda环境配置(安装必要依赖和3DGS相关组件)、以及训练命令执行步骤。文章提供了详细的命令行操作流程,帮助读者快速搭建3DGS训练环境。适合在Linux系统、Nvidia GPU环境下使用,完整教程可参考系列文章

诺有缸的高飞鸟的博客 1757

算法 排序2 Insert or Merge 

全部每周作业和视频思考题答案和解析 见浙江大学 数据结构 思考题+每周练习答案 题目:According to Wikipedia: Insertion sortiterates, consuming one input element each repetition, and growing a sorted output list. Each iteration, insertion ...

Dezeming的博客 6247

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

09-排序2 Insert or Merge(插入和归并)

09-排序2 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 remo...

qq_43791139的博客 373

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

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

最美的时光 1685

PAT 1089 Insert or Merge C++版

PAT 1089 Insert or Merge C++版 1.题意 题意很简单,就是给出一个源数组,然后再给出一个中间数组,让你判断这个中间数组是通过“插入排序”,还是“归并排序”得到? 2.分析 对于这题,主要思路如下: step 1:首先判断是由哪种方法得到这个序列 step 2:如果是插入排序,那么再进行下一步插入,然后输出 step 3:如果是归并排序,那么还需要多知道一点儿事情,就是...

说文科技,做有态度的研究。 648

⭐PAT A1089 Insert or Merge

文章目录题目描述知识点实现码前思考代码实现码后反思 题目描述 给定一个序列A和序列B判断,序列B是序列A的插入排序还是归并排序的中间结果,并且输出序列B的下一步结果。 知识点 排序 实现 码前思考 首先,这道题我并不会做,我做错了,我是看了网上的解答的; 解题思路就是先插入排序一次,判断是否是插入排序,不是就进行归并排序; 这里的归并排序是递推的写法,而不是递归,我之前想错了,看来手动模拟一下测试用例还是非常有必要的! 关于归并排序的递推写法,主要把握两个细节: 每次是合并一系列为step大小的区.

yc_cy1999的博客 275

LeetCode - 56.Merge Intervals & LeetCode - 57.Insert Interval (贪心、插入排序)

LeetCode - 56.Merge Intervals &amp; LeetCode - 57.Insert Interval (贪心、插入排序) LeetCode - 56.Merge Intervals LeetCode - 57.Insert Interval LeetCode - 56.Merge Intervals 题目链接 题目 解析 这题一看就是贪心的题目: 对这些区间...

zxzxin的博客~ 444

1098 Insertion or Heap Sort (25 分) (堆排序和插入排序的特征)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...

Star's blogs 150

07-排序2. 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 dat

进阶的Kaiser@ZJU !!! 882

浙大pat | 浙大pat 牛客网甲级1061 Insert or Merge (25)判断是插入排序还是归并排序

According to Wikipedia:Insertion sort iterates, consuming one input element each repetition, andgrowing a sorted output list. Each iteration, insertion sort removes one element from the input data, fi...

u012737193的博客 628

1089 Insert or Merge (25分)【归并排序、插入排序】

1089Insert or Merge(25分) According to Wikipedia: Insertion sortiterates, consuming one input element each repetition, and growing a sorted output list. Each iteration, insertion sort removes one ...

胡小涛的博客 246
上一篇: 程序员价值观
下一篇: 程序员的好习惯
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值