简单题。判断一下是插排还是堆排。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<algorithm>
using namespace std; const int maxn=;
int a[maxn],b[maxn],n; int main()
{
memset(b,-,sizeof b);
scanf("%d",&n);
for(int i=; i<=n; i++) scanf("%d",&a[i]);
for(int i=; i<=n; i++) scanf("%d",&b[i]); int flag=; int p=n+;
for(int i=; i<=n; i++)
if(b[i]<b[i-])
{
p=i;
break;
} for(int i=p; i<=n; i++)
{
if(a[i]==b[i]) continue;
else flag=;
} if(flag==)
{
printf("Insertion Sort\n");
if(p==n+) p=n;
sort(a+,a+p+);
for(int i=; i<=p; i++)
{
printf("%d",a[i]);
if(i<n) printf(" ");
else printf("\n");
}
for(int i=p+; i<=n; i++)
{
printf("%d",a[i]);
if(i<n) printf(" ");
else printf("\n");
}
}
else
{
printf("Heap Sort\n");
sort(a+,a++n);
for(int i=n; i>=; i--)
{
if(a[i]==b[i]) p=i;
else break;
} swap(b[],b[p-]); int i=;;
while()
{
if(*i<p-&&*i+<p-)
{
if(b[i]<max(b[*i],b[*i+]))
{ if(b[*i]>b[*i+])
{
swap(b[*i],b[i]);
i=*i;
}
else
{
swap(b[*i+],b[i]);
i=*i+;
}
}
else break;
}
else if(*i<p-)
{
if(b[i]<b[*i])
{
swap(b[*i],b[i]);
i=*i;
}
}
else break; }
for(int i=; i<=n; i++)
{
printf("%d",b[i]);
if(i<n) printf(" ");
else printf("\n");
}
} return ;
}

PAT (Advanced Level) 1098. Insertion or Heap Sort (25)的更多相关文章

  1. 【PAT甲级】1098 Insertion or Heap Sort (25 分)

    题意: 输入一个正整数N(<=100),接着输入两行N个数,表示原数组和经过一定次数排序后的数组.判断是经过插入排序还是堆排序并输出再次经过该排序后的数组(数据保证答案唯一). AAAAAcce ...

  2. pat 甲级 1098. Insertion or Heap Sort (25)

    1098. Insertion or Heap Sort (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...

  3. 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 ...

  4. PAT Advanced 1098 Insertion or Heap Sort (25) [heap sort(堆排序)]

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

  5. PAT甲题题解1098. Insertion or Heap Sort (25)-(插入排序和堆排序)

    题目就是给两个序列,第一个是排序前的,第二个是排序中的,判断它是采用插入排序还是堆排序,并且输出下一次操作后的序列. 插入排序的特点就是,前面是从小到大排列的,后面就与原序列相同. 堆排序的特点就是, ...

  6. 1098. Insertion or Heap Sort (25)

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

  7. 1098 Insertion or Heap Sort (25分)

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

  8. PAT甲级——1098 Insertion or Heap Sort (插入排序、堆排序)

    本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/90941941 1098 Insertion or Heap So ...

  9. pat1098. Insertion or Heap Sort (25)

    1098. Insertion or Heap Sort (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...

随机推荐

  1. redis数据类型:sets

    sets类型及操作: set是集合,它是string类型的无序集合.set是通过hash table实现的, 添加.删除和查找的复杂度都是O(1).对集合我们可以取并集.交集.差集. 通过这些操作我们 ...

  2. Scala Tuple类型

    Tuple可以作为集合存储不同类型的数据,初始化实例如下: val tuple = (1,3,3.14,"aa") val third = tuple._3 Tuple 下标访问从 ...

  3. 网页 CSS样式表

    昨天,我主要是对CSS样式表进行了一下复习. CSS样式表主要有三类:内联样式表.内嵌样式表.外部样式表,我们平时一般使用第二种样式表. 选择器主要包括:标签选择器.class选择器.ID选择器.复合 ...

  4. AltiumDesigner14绘制四层板设置

    1,快捷键(O+K)进入板层设置界面: 2,选择AddLayer,里边有两个选项(add layer(添加信号层)||add internal plane(增加平面))  四层板的话一般层次的划分是t ...

  5. 正则表达式 Pattern & Matcher

    1 compile and pattern Pattern类用于创建一个正则表达式,也可以说创建一个匹配模式,它的构造方法是私有的,不可以直接创建,但可以通过Pattern.complie(Strin ...

  6. ios简单更改系统TabBar的高度

    - (void)viewDidLayoutSubviews { [super viewDidLayoutSubviews]; CGRect frame = self.tabBar.frame; fra ...

  7. WINDOWS特有的消息常量标识符

    '========================================'WINDOWS特有的消息常量标识符'======================================== ...

  8. Chapter 2 Open Book——15

    The rest of the week was uneventful. I got used to the routine of my classes. 这周剩下的时间都是平淡无事的.我就是正常的上 ...

  9. 多选出差同事id,拼接,去掉最后逗号

    ===========方法1 substr() ,永远都是.(第一个参数)开始位置.(第二个参数)截取个数 ,负数表示都后面开始数 substr($data['members'],0,strlen($ ...

  10. 二分法习题HDU2199

    AC代码 : #include<iostream>#include<cmath>using namespace std;double y;double f(double n){ ...