上一页 1 ··· 14 15 16 17 18 19 20 21 22 ··· 26 下一页
摘要: Public Bike Management PAT-1018 使用一个vector来存储所有最短路的前驱结点,再通过使用dfs和一个额外的vector记录每一条路径 #include<iostream> #include<cstdio> #include<algorithm> #include<c 阅读全文
posted @ 2020-09-23 10:17 Garrett_Wale 阅读(100) 评论(0) 推荐(0) 编辑
摘要: Cartesian Tree PAT-1167 一开始我使用数组进行存储,但是这样可能会导致无法开足够大的数组,因为树如果是链表状的则无法开这么大的数组(虽然结点很少)。 正确的解法还是需要建树,使用指针。 #include<iostream> #include<cstring> #include< 阅读全文
posted @ 2020-09-22 21:39 Garrett_Wale 阅读(228) 评论(0) 推荐(0) 编辑
摘要: Topological Order PAT-1146 #include<iostream> #include<cstring> #include<string> #include<algorithm> #include<cstdio> #include<sstream> #include<set> 阅读全文
posted @ 2020-09-22 20:39 Garrett_Wale 阅读(203) 评论(0) 推荐(0) 编辑
摘要: Heaps PAT-1147 #include<iostream> #include<cstring> #include<string> #include<algorithm> #include<cstdio> #include<sstream> #include<set> #include<map 阅读全文
posted @ 2020-09-22 19:00 Garrett_Wale 阅读(320) 评论(0) 推荐(0) 编辑
摘要: Travelling Salesman Problem PAT-1150 #include<iostream> #include<cstring> #include<string> #include<algorithm> #include<cstdio> #include<sstream> #inc 阅读全文
posted @ 2020-09-22 18:20 Garrett_Wale 阅读(136) 评论(0) 推荐(0) 编辑
摘要: Vertex Coloring PAT-1154 #include<iostream> #include<cstring> #include<string> #include<algorithm> #include<cstdio> #include<sstream> #include<set> #i 阅读全文
posted @ 2020-09-22 17:09 Garrett_Wale 阅读(119) 评论(0) 推荐(0) 编辑
摘要: Decode Registration Card of PAT PAT-1153 这里需要注意题目的规模,并不需要一开始就存储好所有的满足题意的信息 这里必须使用unordered_map否则会超时 vector的使用需要注意,只有一开始赋予了容量才能读取。 不需要使用set也可以 #include 阅读全文
posted @ 2020-09-21 17:58 Garrett_Wale 阅读(116) 评论(0) 推荐(0) 编辑
摘要: Hashing - Average Search Time PAT-1145 需要注意本题的table的容量设置 二次探测,只考虑正增量 这里计算平均查找长度的方法和书本中的不同 #include<iostream> #include<cstring> #include<string> #inclu 阅读全文
posted @ 2020-09-20 20:20 Garrett_Wale 阅读(306) 评论(0) 推荐(0) 编辑
摘要: Splitting A Linked List PAT-1133 本题一开始我是完全按照构建链表的数据结构来模拟的,后来发现可以完全使用两个vector来解决 一个重要的性质就是位置是相对不变的。 #include<iostream> #include<cstring> #include<strin 阅读全文
posted @ 2020-09-20 18:00 Garrett_Wale 阅读(144) 评论(0) 推荐(0) 编辑
摘要: The Missing Number PAT-1144 #include<iostream> #include<cstring> #include<string> #include<algorithm> #include<cstdio> #include<sstream> #include<set> 阅读全文
posted @ 2020-09-20 12:20 Garrett_Wale 阅读(107) 评论(0) 推荐(0) 编辑
摘要: Werewolf PAT-1148 题目的要点是不管n规模多大,始终只有两个狼人 说谎的是一个狼人和一个好人 紧紧抓住这两点进行实现和分析 #include <iostream> #include <vector> #include <cmath> using namespace std; int 阅读全文
posted @ 2020-09-19 21:19 Garrett_Wale 阅读(179) 评论(0) 推荐(0) 编辑
摘要: Cut Integer PAT-1132 #include<iostream> #include<cstring> #include<string> #include<algorithm> #include<cstdio> #include<sstream> #include<cstdlib> us 阅读全文
posted @ 2020-09-19 19:44 Garrett_Wale 阅读(140) 评论(0) 推荐(0) 编辑
摘要: Look-and-say Sequence PAT-1140 #include<iostream> #include<cstring> #include<string> #include<algorithm> #include<cstdio> #include<sstream> using name 阅读全文
posted @ 2020-09-19 19:14 Garrett_Wale 阅读(101) 评论(0) 推荐(0) 编辑
摘要: A Delayed Palindrome PAT-1136 我这里将数字转换为字符串使用的是stringstream字符串流 扩充:将字符串转换为数字可以使用stoi函数,函数头为cstdlib #include<iostream> #include<cstring> #include<string 阅读全文
posted @ 2020-09-19 17:39 Garrett_Wale 阅读(151) 评论(0) 推荐(0) 编辑
摘要: Google Recruitment PAT-1152 本题最需要注意的是最后输出要以字符串形式输出,否则可能会出现前导0的情况。 /** * @Author WaleGarrett * @Date 2020/9/18 21:14 */ import java.io.*; import java.u 阅读全文
posted @ 2020-09-18 21:42 Garrett_Wale 阅读(133) 评论(0) 推荐(0) 编辑
摘要: 克隆图 LeetCode-133 使用一个map来存储已经遍历的结点,这个存起来的结点必须是新new的才符合题意 /* // Definition for a Node. class Node { public int val; public List<Node> neighbors; public 阅读全文
posted @ 2020-09-12 17:26 Garrett_Wale 阅读(180) 评论(0) 推荐(0) 编辑
摘要: Invert a Binary Tree pat-1102 import java.util.Arrays; import java.util.Queue; import java.util.Scanner; import java.util.concurrent.LinkedBlockingQue 阅读全文
posted @ 2020-09-05 20:35 Garrett_Wale 阅读(90) 评论(0) 推荐(0) 编辑
摘要: Pre- and Post-order Traversals PAT-1119 这题难度较大,主要需要考虑如何实现根据前序遍历和后序遍历来确定一颗二叉树 一篇好的文章: 题解 import java.util.Scanner; /** * @Author WaleGarrett * @Date 20 阅读全文
posted @ 2020-09-05 19:47 Garrett_Wale 阅读(137) 评论(0) 推荐(0) 编辑
摘要: LCA in a Binary Tree PAT-1151 本题的困难在于如何在中序遍历和前序遍历已知的情况下找出两个结点的最近公共祖先。 可以利用据中序遍历和前序遍历构建树的思路,判断两个结点在根节点的左右子树,依次递归找到最近祖先 import java.util.HashMap; import 阅读全文
posted @ 2020-09-05 18:03 Garrett_Wale 阅读(146) 评论(0) 推荐(0) 编辑
摘要: Build A Binary Search Tree PAT-1099 本题有意思的一个点就是:题目已经给出了一颗排序二叉树的结构,需要根据这个结构和中序遍历序列重构一棵二叉排序树。 解法:可以根据中序遍历的思路,首先将给定的序列串进行排序即是中序遍历的结果。接着,根据给定的树结构进行中序遍历,这期 阅读全文
posted @ 2020-09-05 16:55 Garrett_Wale 阅读(156) 评论(0) 推荐(0) 编辑
上一页 1 ··· 14 15 16 17 18 19 20 21 22 ··· 26 下一页