1098 Insertion or Heap Sort (25 分)(堆)
这里的第二序列相当于是排序还没拍好的序列
对于第二个样例的第二个序列其实已经是大顶堆了 然后才进行的堆排序 知道这个就好做了
#include<bits/stdc++.h> using namespace std;
vector<int>a,b;
int n;
void downAdjust(int low,int high)
{
int i=low;
int j=i*;
while(j<=high){
if(j+<=high&&b[j]<b[j+]){
j=j+;
}
if(b[j]>b[i]){
swap(b[j],b[i]);
i=j;
j=i*;
}
else break;
}
}
int main()
{
scanf("%d",&n);
a.resize(n+);
b.resize(n+);
for(int i=;i<=n;i++) scanf("%d",&a[i]);
for(int i=;i<=n;i++) scanf("%d",&b[i]);
int flag=;
while(flag<=n&&b[flag]>=b[flag-]) flag++;
int index=flag;
while(flag<=n&&a[flag]==b[flag]) flag++;
if(flag==n+){
printf("Insertion Sort\n");
sort(b.begin()+,b.begin()++index);
for(int i=;i<=n;i++){
if(i!=) printf(" ");
printf("%d",b[i]);
}
}
else{
printf("Heap Sort\n");
int f=n;
while(f>&&b[f-]<=b[f]){
f--;
} swap(b[],b[f]);
downAdjust(,f-);
for(int i=;i<=n;i++){
if(i!=) printf(" ");
printf("%d",b[i]);
}
}
return ;
}
1098 Insertion or Heap Sort (25 分)(堆)的更多相关文章
- 【PAT甲级】1098 Insertion or Heap Sort (25 分)
题意: 输入一个正整数N(<=100),接着输入两行N个数,表示原数组和经过一定次数排序后的数组.判断是经过插入排序还是堆排序并输出再次经过该排序后的数组(数据保证答案唯一). AAAAAcce ...
- 1098 Insertion or Heap Sort (25分)
According to Wikipedia: Insertion sort iterates, consuming one input element each repetition, and gr ...
- pat 甲级 1098. Insertion or Heap Sort (25)
1098. Insertion or Heap Sort (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...
- PTA 09-排序3 Insertion or Heap Sort (25分)
题目地址 https://pta.patest.cn/pta/test/16/exam/4/question/676 5-14 Insertion or Heap Sort (25分) Accor ...
- PAT (Advanced Level) Practise - 1098. Insertion or Heap Sort (25)
http://www.patest.cn/contests/pat-a-practise/1098 According to Wikipedia: Insertion sort iterates, c ...
- PAT (Advanced Level) 1098. Insertion or Heap Sort (25)
简单题.判断一下是插排还是堆排. #include<cstdio> #include<cstring> #include<cmath> #include<ve ...
- PAT Advanced 1098 Insertion or Heap Sort (25) [heap sort(堆排序)]
题目 According to Wikipedia: Insertion sort iterates, consuming one input element each repetition, and ...
- 1098. Insertion or Heap Sort (25)
According to Wikipedia: Insertion sort iterates, consuming one input element each repetition, and gr ...
- PAT甲题题解1098. Insertion or Heap Sort (25)-(插入排序和堆排序)
题目就是给两个序列,第一个是排序前的,第二个是排序中的,判断它是采用插入排序还是堆排序,并且输出下一次操作后的序列. 插入排序的特点就是,前面是从小到大排列的,后面就与原序列相同. 堆排序的特点就是, ...
- 09-排序3 Insertion or Heap Sort (25 分)
According to Wikipedia: Insertion sort iterates, consuming one input element each repetition, and gr ...
随机推荐
- 【luogu P1195 口袋的天空】 题解
题目链接:https://www.luogu.org/problemnew/show/P1195 嗯~我是被题目背景吸引到才做的,想吃棉花糖啦! 话说回来,这道题其实很容易就能想明白,k棵最小生成树. ...
- lucene&solr学习——分词器
下图是语汇单元的生成过程: 从一个Reader字符流开始,创建基于Reader的Tokenizer分词器,经过三个TokenFilter生成语汇单元Tokens. 要看分词器的分析效果,只需要看Tok ...
- 数据库:DDL/DML/DCL/TCL基本概念
SQL(Structure Query Language)语言是数据库的核心语言 1. 数据查询语言DQL 数据查询语言DQL基本结构是由SELECT子句,FROM子句,WHERE 子句组成的查询块: ...
- javascript跳转页面
<script type="text/javascript"> function openNewTab() { parent.addExampleTab({ id: a ...
- 极光推送小结 - iOS
此次即友盟分享小结(友盟分享小结 - iOS)之后对推送也进行了一版优化.此次分享内容依然基于已经成功集成 SDK 后 code 层级部分. 注:此次分享基于 SDK 3.1.0,若版本相差较大,仅供 ...
- 5820. 【NOIP提高A组模拟2018.8.16】 非法输入(模拟,字符串)
5820. [NOIP提高A组模拟2018.8.16] 非法输入 (File IO): input:aplusb.in output:aplusb.out Time Limits: 1000 ms ...
- 微信订阅号 获取用户基本信息,登录及 php
<?php //echo file_get_contents("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_cr ...
- ansible-palybook剧本
1 ansible基础知识部分补充 1.1 ansible软件特点: · 可以实现批量管理 · 可以实现批量部署 · ad-hoc(批量执行命令)---针对临时性的操作 ansible clsn -m ...
- PHP计算翻页
function fanye() { if ($total <= $num) { $list['curTotal'] = $total; } else { $offsetA = $start; ...
- php将html页面截图并保存成图片
采用html5的canvas,将图片绘制到画布上,然后用canvas的 toDataURL 方法. 但是在图片转base64的过程中遇到了两个问题, 1:图片无法绘制,转成的base64 用浏览器打开 ...