mirror of
https://github.com/xlucn/PAT.git
synced 2026-11-05 06:37:35 +08:00
28 lines
2.1 KiB
HTML
28 lines
2.1 KiB
HTML
插入与归并
|
||
<div class="ques-view"><p>根据维基百科的定义:</p>
|
||
<p><strong>插入排序</strong>是迭代算法,逐一获得输入数据,逐步产生有序的输出序列。每步迭代中,算法从输入序列中取出一元素,将之插入有序序列中正确的位置。如此迭代直到全部元素有序。</p>
|
||
<p><strong>归并排序</strong>进行如下迭代操作:首先将原始序列看成 N 个只包含 1 个元素的有序子序列,然后每次迭代归并两个相邻的有序子序列,直到最后只剩下 1 个有序的序列。</p>
|
||
<p>现给定原始序列和由某排序算法产生的中间序列,请你判断该算法究竟是哪种排序算法?</p>
|
||
<h3 id="-">输入格式:</h3>
|
||
<p>输入在第一行给出正整数 N (<span class="katex"><span class="katex-mathml"><math><mrow><mo>≤</mo></mrow>\le</math></span><span aria-hidden="true" class="katex-html"><span class="strut" style="height:0.63597em;"></span><span class="strut bottom" style="height:0.7719400000000001em;vertical-align:-0.13597em;"></span><span class="base textstyle uncramped"><span class="mrel">≤</span></span></span></span>100);随后一行给出原始序列的 N 个整数;最后一行给出由某排序算法产生的中间序列。这里假设排序的目标序列是升序。数字间以空格分隔。</p>
|
||
<h3 id="-">输出格式:</h3>
|
||
<p>首先在第 1 行中输出<code>Insertion Sort</code>表示插入排序、或<code>Merge Sort</code>表示归并排序;然后在第 2 行中输出用该排序算法再迭代一轮的结果序列。题目保证每组测试的结果是唯一的。数字间以空格分隔,且行首尾不得有多余空格。</p>
|
||
<h3 id="-1-">输入样例 1:</h3>
|
||
<pre><code class="lang-in">10
|
||
3 1 2 8 7 5 9 4 6 0
|
||
1 2 3 7 8 5 9 4 6 0
|
||
</code></pre>
|
||
<h3 id="-1-">输出样例 1:</h3>
|
||
<pre><code class="lang-out">Insertion Sort
|
||
1 2 3 5 7 8 9 4 6 0
|
||
</code></pre>
|
||
<h3 id="-2-">输入样例 2:</h3>
|
||
<pre><code class="lang-in">10
|
||
3 1 2 8 7 5 9 4 0 6
|
||
1 3 2 8 5 7 4 9 0 6
|
||
</code></pre>
|
||
<h3 id="-2-">输出样例 2:</h3>
|
||
<pre><code class="lang-out">Merge Sort
|
||
1 2 3 8 4 5 7 9 0 6
|
||
</code></pre>
|
||
</div> |