自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(23)
  • 收藏
  • 关注

原创 PAT甲级题目目录

树 1004 Counting Leaves 1020 Tree Traversals

2022-03-11 16:10:09 294

原创 1155 Heap Paths 分数 30

PAT题目目录 判断是非为堆,进一步判断是否为大根堆、小根堆。 1用数组存储这个完全二叉树; 2遍历,找出所有从根节点到叶节点的路径,同时用(bool) gt lt记录是否存在当前节点比前一个结点大或小的情况; 3根据gt lt的状态判断是否为堆、大根堆、小根堆。...

2022-06-19 18:41:17 223 1

原创 1106 Lowest Price in Supply Chain 分数 25

供应链最低价格,即求树的最短距离,采用记忆搜索、dfs深度优先的方法。

2022-06-14 20:38:09 110

原创 1090 Highest Price in Supply Chain 分数 25

题目链接 #include <iostream> #include <cstring> #include <cmath> using namespace std; const int N=1e5+10; int n; double P,R; int p[N],f[N]; int dfs(int u){ if(f[u]!=-1) return f[u]; if(p[u]==-1) return f[u]=0; return f[u]=dfs(p[u]

2022-05-10 21:24:50 137

原创 1079 Total Sales of Supply Chain 分数 25

题目链接 #include <iostream> #include <algorithm> #include <cmath> #include <cstring> using namespace std; const int N=100010; double P,R; int n; int p[N],f[N];//父节点,距离 int cnt[N];//子节点的营业额 int dfs(int u){ if(f[u]!=-1) return f[u];

2022-05-10 20:46:34 99

原创 1094 The Largest Generation 分数 25

PAT题目目录 #include <iostream> #include <vector> using namespace std; const int N=110; bool g[N][N]; int n,m; vector<int> level[N]; int main(){ cin>>n>>m; for(int i=1;i<=m;i++){ int id,k;cin>>id>>k;

2022-05-06 21:17:43 103

原创 1053 Path of Equal Weight 分数 30

PAT题目目录 #include <iostream> #include <algorithm> #include <cstring> #include <vector> using namespace std; const int N=1e4+10; int n,m,sum; bool g[N][N]; int w[N]; vector< vector<int> >ans; void dfs(int u,int s,vector&lt

2022-05-06 19:44:59 78

原创 1135 Is It A Red-Black Tree 分数 30

PAT题目目录 #include <iostream> #include <algorithm> #include <unordered_map> using namespace std; unordered_map<int,int> pos; bool ans; const int N=40; int pre[N],in[N]; int build(int il,int ir,int pl,int pr,int &sum){ int root

2022-04-27 21:16:30 182

原创 1123 Is It a Complete AVL Tree 分数 30

PAT题目目录 #include <iostream> #include <algorithm> using namespace std; const int N=30; int n; int l[N],r[N],v[N],h[N],idx=0; int q[N],pos[N]; void update(int u){ h[u]=max(h[l[u]],h[r[u]])+1; } int get_balance(int u){ return h[l[u]]-h[r[u

2022-04-26 20:09:38 72

原创 1066 Root of AVL Tree 分数 25

PAT题目链接 #include <iostream> #include <algorithm> using namespace std; int n; const int N=30; int l[N],r[N],v[N],h[N],idx=0;//l[编号]=左儿子编号,v[编号]=权值,h[编号]=高度 int get_balance(int u){ return h[l[u]]-h[r[u]]; } void update(int u){ h[u]=max(h[

2022-04-25 21:10:34 168

原创 1138 Postorder Traversal (25 分)

PAT题目链接 #include <iostream> #include <unordered_map> using namespace std; const int N=5e4+10; int n,post;//post记录后序遍历的第一个 int pre[N],in[N];//前序和中序遍历 unordered_map <int,int> post_in; void built(int il,int ir,int pl,int pr){ int root=pr

2022-04-19 21:21:14 89

原创 1127 ZigZagging on a Tree (30 分)

PAT题目链接 Z字形遍历二叉树 #include <iostream> #include <algorithm> #include <unordered_map> using namespace std; const int N=35; int n; int in[N],post[N],q[N]; unordered_map <int,int> l,r,pos; int built(int il,int ir,int pl,int pr){ //参数

2022-04-12 20:53:16 75

原创 1119 Pre- and Post-order Traversals (30 分)

PAT目录 #include <iostream> using namespace std; const int N=35; int n; int pre[N],post[N]; int dfs(int l1,int r1,int l2,int r2,string &in){ if(l1>r1) return 1; if(pre[l1]!=post[r2]) return 0; int cnt; for(int i=0;i<=r1;i++){

2022-04-08 20:55:49 60

原创 1115 Counting Nodes in a BST (30 分)

PAT目录 #include <iostream> using namespace std; const int N=1010; int n; int l[N],r[N],w[N],idx=0; int cnt[N],max_depth=0; void insert(int &u,int ww){ //u前面要加&,例如开始root=0,加入25之后root=1(记录编号),主函数当中的root应该也随着变化 if(!u) u=++idx,w[u]=ww;

2022-04-06 19:05:50 55

原创 1110 Complete Binary Tree (25 分)

PAT目录 #include <iostream> #include <cstring> using namespace std; int n; const int N=25; int l[N],r[N]; int maxk,maxid; bool hasfather[N]; void dfs(int u,int k){ if(u==-1) return; if(k>maxk) maxk=k,maxid=u; if(l[u]!=-1) dfs(l[u],

2022-04-01 21:20:13 59

原创 1102 Invert a Binary Tree (25 分)

#include <iostream> #include <algorithm> #include <cstring> using namespace std; int n; const int N=15; int l[N],r[N],q[N]; bool hasfather[N]; void traversal(int root){ if(root==-1) return; traversal(l[root]); traversal(r[root

2022-04-01 20:35:24 249

原创 1086 Tree Traversals Again (25 分)

An inorder binary tree traversal can be implemented in a non-recursive way with a stack. For example, suppose that when a 6-node binary tree (with the keys numbered from 1 to 6) is traversed, the stack operations are: push(1); push(2); push(3); pop(); pop(

2022-03-30 20:51:59 100

原创 1064 Complete Binary Search Tree (30 分)

#include <iostream> #include <algorithm> using namespace std; const int N=1010; int n; int w[N],tr[N];//w存放的是输入的权值。tr存放的是树的层次遍历,也就是完全二叉树的数组存储 void inorder(int u,int &k){ if((u<<1)<=n) inorder(u<<1,k); tr[u]=w[k++];

2022-03-29 16:43:47 301

原创 1043 Is It a Binary Search Tree (25 分)

#include <cstring> #include <iostream> #include <algorithm> using namespace std; const int N=1010; int n,cnt;//后序遍历用cnt int preorder[N],inorder[N],postorder[N]; bool built(int il,int ir,int pl,int pr,int type){ if(il>ir) return tru

2022-03-28 21:24:44 55

原创 1099 Build A Binary Search Tree (30 分)

#include <iostream> #include <algorithm> using namespace std; const int N=110; int n; int l[N],r[N];//存放左右子树的序号 int q[N]; int a[N],w[N]; void inorder(int u,int &k){//u为序号 if(u==-1) return; inorder(l[u],k); w[u]=a[k++]; ino

2022-03-28 21:21:54 252

原创 1021 Deepest Root (25 分)

A graph which is connected and acyclic can be considered a tree. The height of the tree depends on the selected root. Now you are supposed to find the root that results in a highest tree. Such a root is called the deepest root. Input Specification: Each in

2022-03-11 16:07:42 211

原创 PAT1004 Counting Leaves (30 分)

A family hierarchy is usually presented by a pedigree tree. Your job is to count those family members who have no child. Input Specification: Each input file contains one test case. Each case starts with a line containing 0<N<100, the number of nodes

2022-03-11 10:29:52 153

原创 PAT1020 Tree Traversals (25 分)

Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and inorder traversal sequences, you are supposed to output the level order traversal sequence of the corresponding binary tree. **Input Specificat Each input fi

2022-03-11 10:24:30 199

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除