PTA 1147 Heaps(30 分)

拆解全球18大“支付清算”体系:CLS、中国、美国、欧洲、日本、mBridge... 阅读详情

题意:判断是最大堆还是最小堆或者不是堆
思路:直接分析i i*2 i*2+1之间的关系
注意点:输入的数字是在int范围内的所有数字,一开始的时候,我把数组置空成-1的然后错了好几个样例,回去看看题目,然后加了一个数组判断这个点是不是节点就可以了

#include<bits/stdc++.h>
using namespace std;
int tree[10050];
int isnode[10050];
int n,m;
int maxh(){
    for(int i=m;i>1;i--){
        if(tree[i/2]>=tree[i])
        continue;
        else
            return 0;
    }
    return 1;
}
void printh(int i){
    if(isnode[i*2]!=-1)
    printh(i*2);
    if(isnode[i*2+1]!=-1)
    printh(i*2+1);
    if(isnode[i]!=-1){
        if(i==1)
        cout<<tree[i]<<endl;
        else
        cout<<tree[i]<<" ";
    }
}
int minh(){
    for(int i=m;i>1;i--){
        if(tree[i/2]<=tree[i])
        continue;
        else
            return 0;
    }
    return 1;
}
int main(){ 
    cin>>n>>m;
    for(int i=0;i<n;i++){
        memset(isnode,-1,sizeof(isnode));       
        for(int j=1;j<=m;j++){
            cin>>tree[j];
            isnode[j]=1;
        }
        if(m==1){
            cout<<"Not Heap\n";
            printh(1);
            continue;   
        }

        int f=maxh();
        if(f==1){
            cout<<"Max Heap"<<endl;
            printh(1);
            continue;
        }
        f=minh();
        if(f==1){
            cout<<"Min Heap"<<endl;
            printh(1);
            continue;           
        }
        cout<<"Not Heap"<<endl;
        printh(1);
    }

    return 0;
}
VB摄像头监控 该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制 立即下载

相关推荐

Kali Linux下John the Ripper实战:从识别yescrypt哈希到破解zip压缩包(保姆级避坑指南)

本文详细介绍了在Kali Linux中使用John the Ripper工具从识别yescrypt哈希到破解zip压缩包的全过程。针对常见的'No password hashes loaded'报错,提供了两种解决方案,并扩展讲解了哈希识别、zip文件破解及性能优化技巧,是安全测试人员的实用指南。

weixin_29323365的博客 236

1147 Heaps(30 分)

1147 Heaps(30 分) In computer science, a heap is a specialized tree-based data structure that satisfies the heap property: if P is a parent node of C, then the key (the value) of P is either greater t...

galesaur_wcy 870

第二章-Ethernet/IP基本概念

在I/O连接中,一旦连接建立,就不会有请求-响应数据,只会按照连接建立时指定的生产触发器所确定的时间间隔生产和消耗带有ConnectionID的数据。连接是通过连接管理器对象的Forward请求服务建立的,ForwardOpen请求包含所有连接参数,包括传输类、生产触发器、定时信息、电子密钥和连接ID。I/O适配器:I/O适配器从I/O扫描器接收隐式通信连接请求,然后以请求的速率生成I/O数据。I/O扫描器:启动与I/O适配器的隐式通信,需要处理连接的配置以及如何配置适配器。扫描器还支持启动显式报文。

_Nooice的博客 1233

爆刷PAT(甲级)——之【1147】 Heaps(30 分)——堆的判别

艰难的英语单词:postorder traversal   后序遍历 题意:给一个完全二叉树,判断是最大堆还是最小堆还是都不是。 难点:完全二叉树用数组存的时候(个人习惯下标从1开始),左孩子节点是父亲节点*2,右孩子是父亲节点*2+1。对于一个玩完全二叉树来说,N个节点,那么有N/2个叶子! 知道上面知识点以后,本题就很简单,从节点1到N/2,判断是否都符合最大堆或者最小堆特性,否则就什么...

Hide_in_Code 517

BAPI创建委外采购订单

使用BAPI BAPI_PO_CREATE1创建委外采购订单,组件为手工输入时,有几个点需要注意: 1、已通过CS01创建过BOM的物料,创建时会自动带出components。如果要修改当前组件清单,可以通过设置pocomponents-change_id = 'E’来实现 lv_sline = lv_sline + 1. ls_pocomponents-po_item = l_ebelp + 10. ls_pocomponents-ITEM_NO = l

Buffalo_soldier的博客 3262

各种逻辑漏洞

注册:短信轰炸验证码安全问题密码爆破邮箱轰炸用户任意注册、批量注册用户名枚举XSS(有框的地方就可以尝试插XSS)登录:短信轰炸、验证码安全问题、密码爆破、邮箱轰炸SQL注入撞库抓包把password字段修改为空值发送认证凭证替换、比如返回的数据包中包含账号,修改账号就能登录到其他账号Cookie仿冒修改返回包的相关数据,可能会登陆到其他的用户找回密码:短信邮箱轰炸、短信邮箱劫持重置任意用户账户密码、验证码手机用户未统一验证直接跳过验证步骤。

shirlly_的博客 2093

PAT 甲级 1147 Heaps (30 分)

这题太太太坑爹了,不建树感觉不出来,写的很轻松,建了树就会发现题目是真的坑; 题目里明确讲是N distinct integer,但是在设计测试用例的时候,最后一个测试点在同一颗树里其实是有相同的数的; 感觉自己被出题的玩了@_@ 思路: 1.思路很简单,每一树的序列,第i个和第2i+1、2i+2比较大小(如果这两个存在的话); 2.递归后序遍历二叉树; 代码: #include<iostr...

Yuhan的博客 375

学Simulink——基于Simulink的Buck-Boost变换器双闭环PI+抗饱和设计建模示例

本文详细介绍了基于Simulink的非反相Buck-Boost变换器双闭环控制设计方法。针对Buck-Boost变换器特有的右半平面零点(RHPZ)和控制挑战,提出了电压-电流双闭环PI控制架构,并集成抗积分饱和机制。通过Simulink建模,实现了主电路、电流内环PI、电压外环PI、PWM及占空比限幅等模块的搭建,验证了在输入电压跌落(20V→10V)和负载突变(2A→4A)等场景下的稳定性能。仿真结果表明,输出电压波动小于0.35V,恢复时间快于1ms,电感电流有效限幅。文章还讨论了工程实践要点和扩展方

xiaoheshang_123的博客 318

1147 Heaps (30 分) 堆的判断 静态树

In computer science, a heap is a specialized tree-based data structure that satisfies the heap property: if P is a parent node of C, then the key (the value) of P is either greater than or equal to (i...

辣鸡的博客 375

【SAP HANA 46】关于HANA CPU高峰到 80-100%

关于HANA CPU高峰到 80-100%

探索 Java 编程的技巧、最佳实践和解决方案。本博客提供针对 Java 开发者的实用指南,涵盖从基础到高级话题,旨在提升编程效率和技能。 429

VS2019 C# 连接IBM DB2数据库并查询数据表

操作系统:win10 64位 C#:VS2019 数据库:IBM DB2v11.1_win64_expc 其他工具:IBM Data Studio ibm_ds4130_win 步骤一:使用命令行或是IBM DB2工具:Data Studio,创建一个数据库。这里名称为:Student CREATE DATABASE "Student" AUTOMATIC STORAGE YES ...

坚韧与专注 3796

PTA 1147 Heaps (30分)

题目链接:Heaps 思路: 根据层次遍历建树。 从根节点做一次dfs,记录每个节点的父节点。 依次检查每一个元素是否合法即可,即但凡有一个元素大于父亲元素就不是Max Heap,但凡有一个元素小于父亲元素就不是Min Heap。 代码实现: #include <bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<int,int> PII; typedef struct Tnode *p;

AAmiu的博客 182

PX4控制云台的两种方式 方法适用控舵机 控灯

云台控制插件是mount_control,运行mavros启动文件的时候需要注意该插件是否正常启动,需要在px4_pluginlists.yaml配置文件中将mount_control从blacklisted中移除后才可启动。后会默认占用AUX端口1-4,此时通过AUX通道1-4输出PWM控制信号至云台,对应的RC通道映射功能失效。控制信号输入为RC 则接收机必须连接对应的通道至AUX辅助通道,并通过MNT_MAN_*参数设置pitch/roll/yaw对应的AUX通道。配置为AUTO或MAVLINK,

z1872385的博客 3669

PAT 甲级 1147 Heaps (30 分) 堆+后序遍历

题意: 层次遍历给定一个堆,问是不是最大堆最小堆,然后输出后序遍历 思路: 直接用数组存堆,类似完全二叉树,下标从1开始:父结点下标 i ,则左孩子下标2*i ,右孩子下标 2*i+1 然后分别判断大小堆 后序遍历输出用递归 #include<bits/stdc++.h> #include<cstring> #define FI first #defi...

床前明月光 297

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

PAT (Advanced Level) Practice 1147 Heaps (30 分)堆

In computer science, a heap is a specialized tree-based data structure that satisfies the heap property: if P is a parent node of C, then the key (the value) of P is either greater than or equal to (i...

zamaochick的博客 268

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

【题解】【PAT甲】1147 Heaps (30 分)(堆)

题目链接 题目描述 题目大意 解题思路 题解

Elephant_King的博客 638

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

PTA甲级 1147 Heaps (C++)

In computer science, a heap is a specialized tree-based data structure that satisfies the heap property: if P is a parent node of C, then the key (the value) of P is either greater than or equal to (in a max heap) or less than or equal to (in a min heap) t

Misdirection 162

PTA甲级考试真题练习147——1147 Heaps

题目 思路 水题 代码 #include <iostream> #include <vector> using namespace std; vector<int> vec,post; int n, m; int mark[2]; void DFS(int i){ int pa = i/2; if (pa) { if (vec[pa] < ve...

醉等佳人归 231

【PTA Advanced】1147 Heaps(C++)

1147 Heaps

Trapped_beast的博客 550

PTA 甲级 1147 Heaps

【代码】PTA 甲级 1147 Heaps。

weixin_52030057的博客 122

PAT —1147 Heaps (30)

因为对自己不太自信,所以才报了甲级-  -然后从后往前刷题,30分钟做完第一道之后,我觉得我应该报顶级的,不过无所谓了,先考着甲级吧。In computer science, a heap is a specialized tree-based data structure that satisfies the heap property: if P is a parent node of C, ...

qq_25175067的博客 331

【题解】【PAT甲】1155 Heap Paths (30 分)(堆)

题目链接 PTA | 程序设计类实验辅助教学平台 题目描述 In computer science, aheapis a specialized tree-based data structure that satisfies the heap property: if P is a parent node of C, then the key (the value) of P is either greater than or equal to (in a max heap) or l...

Elephant_King的博客 175

阿马的PAT冒险记(一)

阿马的PAT冒险记(一) 很久很久以前,有一个富饶的王国,王国里有一颗全世界都独一无二的AC宝石,据说只要有了这颗宝石,你做的每一道算法、每一个项目都能AC。可惜,王国被巨龙袭击,宝石下落不明,据说已经被巨龙放进来它的宝库,那是一座叫PTA的城堡...... 阿马从小就想成为一名秃头,哦不,是厉害的程序员,但笨笨的他始终无法领悟到编程的真谛,于是他想,如果能得到那颗传说中的宝石,也许他就是世上最厉害的程序员了。于是,阿马踏上了寻找AC宝石的道路。 这天阿马来到了PTA城堡的面前,升起的阳光笼罩着广袤的森林,

weixin_43916036的博客 175

PAT甲级目录

树(23) 备注 1004Counting Leaves 1020 Tree Traversals 1043 Is It a Binary Search Tree 判断BST,BST的性质 1053 Path of Equal Weight 1064 Complete Binary Search Tree ...

weixin_33840661的博客 149

PTA L2-012 关于堆的判断 (最小堆)

L2-012关于堆的判断(25 分) 将一系列给定数字顺序插入一个初始为空的小顶堆H[]。随后判断一系列相关命题是否为真。命题分下列几种: x is the root:x是根结点; x and y are siblings:x和y是兄弟结点; x is the parent of y:x是y的父结点; x is ...

xcatf的博客 608

Huffman codes

05-树9Huffman Codes(30分) In 1953, David A. Huffman published his paper "A Method for the Construction of Minimum-Redundancy Codes", and hence printed his name in the history of computer scie...

weixin_30496431的博客 615
上一篇: PTA 1014 Waiting in Line
下一篇: PTA 1144 The Missing Number
dpdpd
博客等级 码龄11年 3粉丝 37原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值