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

#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. E - Triangle

    Description Johnny has a younger sister Anne, who is very clever and smart. As she came home from th ...

  2. User already has more than 'max_user_connections' active connections

    vi /etc/my.cnf修改  max_user_connections 参数的数值,重启 MySQL 服务器

  3. Adobe flash CC 汉化破解方法

    转载整理自:http://www.sdifenzhou.com/flashprofessionalcc.html 断网,解压下载的破解dmg文件得到这些文件 第一步,解压安装包,安装,并打开,不要输入 ...

  4. ACPI

    高级配置与电源接口(Advanced Configuration and Power Interface),简称ACPI.1997年由Intel.Microsoft.Toshiba 所共同制定提供操作 ...

  5. InnoDB表要建议用自增列做主键

    InnoDB引擎表是基于B+树的索引组织表(IOT): 每个表都需要有一个聚集索引(clustered index): 所有的行记录都存储在B+树的叶子节点(leaf pages of the tre ...

  6. Ant 删除目录 vs 清空目录

    Apache Ant 可以用下面的命令来删除目录 <delete dir="${lucene.dir}"/> 但是这会删除整个目录,而我现在只想清空目录内的所有文件和子 ...

  7. [PHP] 安装和配置

    Apachehttpd-2.2.19-win64mysql5.6Phphttp://www.php.net/downloads.php 5.4Phpeclipsehttp://www.phpeclip ...

  8. chrome浏览器debug

    Chrome浏览器审查元素 1.Elements标签页 Elements标签页的左侧就是对页面HTML结构的查看与编辑,你可以直接在某个元素上双击修改元素的属性. 1.Edit as HTML直接对元 ...

  9. HDU 5543 Pick The Sticks

    背包变形.与普通的背包问题不同的是:允许有两个物品可以花费减半. 因此加一维即可,dp[i][j][k]表示前i个物品,有j个花费减半了,总花费为k的情况下的最优解. #pragma comment( ...

  10. HDU 2732 Leapin' Lizards

    网络最大流+拆点.输出有坑!!! #include<cstdio> #include<cstring> #include<string> #include<c ...