随笔分类 -  pat甲级

摘要:7 1 Knuth洗牌法 (20分) Knuth 洗牌法是生成 { 1, 2, ..., n } 的一个随机重排列的算法。与每次反复随机生成一个数字,直到获得一个不重复的新数字的算法不同,Knuth 洗牌法从原始序列 { 1, 2, ..., n } 开始,逐次洗牌。洗牌的方法是从左到右,每轮从没确 阅读全文
posted @ 2020-05-02 11:47 yxdh 阅读(983) 评论(0) 推荐(0)
摘要:1150 Travelling Salesman Problem (25分) The "travelling salesman problem" asks the following question: "Given a list of cities and the distances betwee 阅读全文
posted @ 2020-03-15 23:47 yxdh 阅读(140) 评论(0) 推荐(0)
摘要:1148 Werewolf Simple Version (20分) Werewolf(狼人杀) is a game in which the players are partitioned into two parties: the werewolves and the human beings. 阅读全文
posted @ 2020-03-14 23:26 yxdh 阅读(167) 评论(0) 推荐(0)
摘要:1154 Vertex Coloring (25分) A proper vertex coloring is a labeling of the graph's vertices with colors such that no two vertices sharing the same edge 阅读全文
posted @ 2020-03-13 00:31 yxdh 阅读(125) 评论(0) 推荐(0)
摘要:1153 Decode Registration Card of PAT (25分) A registration card number of PAT consists of 4 parts: the 1st letter represents the test level, namely, T 阅读全文
posted @ 2020-03-13 00:27 yxdh 阅读(255) 评论(0) 推荐(0)
摘要:1105 Spiral Matrix (25分) This time your job is to fill a sequence of N positive integers into a spiral matrix in non increasing order. A spiral matrix 阅读全文
posted @ 2020-03-11 23:14 yxdh 阅读(114) 评论(0) 推荐(0)
摘要:1087 All Roads Lead to Rome (30分) Indeed there are many different tourist routes from our city to Rome. You are supposed to find your clients the rout 阅读全文
posted @ 2020-03-11 22:39 yxdh 阅读(207) 评论(0) 推荐(0)
摘要:1119 Pre and Post order Traversals (30分) Suppose that all the keys in a binary tree are distinct positive integers. A unique binary tree can be determ 阅读全文
posted @ 2020-03-06 21:54 yxdh 阅读(130) 评论(0) 推荐(0)
摘要:/ 根据中序遍历 先序遍历构建 输出后序遍历 后序遍历为左右根 递归的返回条件中序遍历中 左子树和右子树 1. 过i将中序遍历中的树分为左子树和右子树 (i为中序遍历的根节点(需要输出的结点(每棵树都是自己 的根结点)) 2.确定左子树的start,与 end范围,同时通过先序数组找到此时的根节点( 阅读全文
posted @ 2020-03-05 19:56 yxdh 阅读(351) 评论(0) 推荐(0)
摘要:"pat 1155 Heap Paths" 阅读全文
posted @ 2020-03-05 19:49 yxdh 阅读(133) 评论(0) 推荐(0)
摘要:"1123 Is It a Complete AVL Tree " 同类型题: pat:1066 输出AVL树最后的根结点 rebalancing is done to restore this property. :重新平衡是为了恢复这个属性 differ by at most one : 最多相 阅读全文
posted @ 2020-03-05 19:43 yxdh 阅读(108) 评论(0) 推荐(0)
摘要:"1098 Insertion or Heap Sort" 单词: 思路: 首先判断插入排序, 当找到一个点 a[i 1] a[i] , i就是不适配点 ​ 如果不适配位置后 排序序列的位置 和 未 排序的位置所有点值都相同,那么就是插入排序 ​ 否则 就是堆排序, 因为堆排序的序列后部已经排好序 阅读全文
posted @ 2020-03-05 19:42 yxdh 阅读(117) 评论(0) 推荐(0)
摘要:"1147 Heaps " 英语 思路 完全二叉树的性质 ​ 判断是否是大顶堆,小顶堆, 只需要判断父节点和子结点是否满足堆的性质 需要注意的是 if( 1) 可以输出元素, if(0)此时非 阅读全文
posted @ 2020-03-05 19:30 yxdh 阅读(100) 评论(0) 推荐(0)
摘要:"pat 1151 LCA in a Binary Tree" 起神解析很完善 暴力版 LCA方法: 关键代码: 优质博客:https://blog.csdn.net/Q_M_X_D_D_/article/details/90047735 阅读全文
posted @ 2020-03-05 19:19 yxdh 阅读(160) 评论(0) 推荐(0)