PAT
从舟
这个作者很懒,什么都没留下…
展开
-
DFS遍历树 求最小叶子高度及个数 1106题
1106 Lowest Price in Supply Chain (25分)A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer.Starting...原创 2020-04-24 21:54:44 · 228 阅读 · 0 评论 -
先序 / 后序 实现树的遍历 1119题
#双数组 ——实现树的遍历原创 2020-04-24 11:55:28 · 209 阅读 · 0 评论 -
并查集(1114题 1118题)
想原创 2020-04-21 10:19:21 · 115 阅读 · 0 评论 -
递归建BST
Sample Input:925 30 42 16 20 20 35 -5 28由输入建立一棵BST树struct node{ int v; struct node *left, *right;};////build主要是要得到root,root代表一整棵树node* build(node *root, int a){ if(roo...原创 2020-04-21 10:09:23 · 158 阅读 · 0 评论 -
Dijkstra
关键点:初始化fill(dis, dis + 510, inf);fill(e[0], e[0] + 510 * 510, inf);dis[起始点] = 0;同时要考虑一些其他要更新的数组全局和起始点初始化二重循环——内部u,v两个版块大循环for(int i = 0; i < n; i++) {int u = -1, minn = inf;for(int j...原创 2020-04-20 11:20:25 · 106 阅读 · 0 评论 -
PAT:1103 Integer Factorization (30分)[深度优先搜索DFS]
基本题意:从数组v中选出符合条件的数:k个,和为n , index和最大。void dfs(int index, int tempSum, int tempK, int facSum) {if (tempK == k) {if (tempSum == n && facSum > maxFacSum) {ans = tempAns;maxFacSum = facSum...原创 2020-04-04 09:58:28 · 155 阅读 · 0 评论 -
PAT:1102 Invert a Binary Tree (25分)
#include<iostream>#include<vector>#include<algorithm>using namespace std;struct node{ int val,index; //leve作为参数,遍历得到 index至关重要,保证了由中序得到层序的稳定性 int left,right,leve;}tree...原创 2020-04-03 23:41:15 · 59 阅读 · 0 评论 -
PAT:1101 Quick Sort (25分)
#include<iostream>#include<vector>#include<map>#include<algorithm>#include<string>using namespace std;int main(){ int n; cin >> n; vector<int>a(n),b(...原创 2020-04-03 11:35:48 · 66 阅读 · 0 评论 -
PAT:1100 Mars Numbers (20分)
#include<iostream>#include<string>using namespace std;string a[13] = {"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug","sep", "oct", "nov", "dec"};string b[13] = {"####"...原创 2020-04-03 09:33:07 · 72 阅读 · 0 评论