PAT
Guapifang
这个作者很懒,什么都没留下…
展开
-
PAT甲级 1131 Subway Map (30分)--堆优化迪杰斯特拉最短路+DFS(两种解法)
1131 Subway Map (30分)In the big cities, the subway systems always look so complex to the visitors. To give you some sense, the following figure shows the map of Beijing subway. Now you are supposed to help people with your computer skills! Given the start原创 2020-08-30 22:48:31 · 239 阅读 · 0 评论 -
PAT甲级 1119 Pre- and Post-order Traversals (30分)二叉树的前序和后序遍历
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 determined by a given pair of postorder and inorder traversal sequences, or preorder and inorder traversal sequ原创 2020-08-29 14:12:07 · 265 阅读 · 0 评论 -
PAT甲级 1066 Root of AVL Tree (25分)--平衡二叉树裸题模板题
**1066 Root of AVL Tree (25分)**An AVL tree is a self-balancing binary search tree. In an AVL tree, the heights of the two child subtrees of any node differ by at most one; if at any time they differ by more than one, rebalancing is done to restore this原创 2020-08-28 23:48:02 · 159 阅读 · 0 评论 -
PAT甲级 1068 Find More Coins (30分) 01背包+路径更新
**1068 Find More Coins (30分)**Eva loves to collect coins from all over the universe, including some other planets like Mars. One day she visited a universal shopping mall which could accept all kinds of coins as payments. However, there was a special re原创 2020-08-20 22:39:35 · 141 阅读 · 1 评论 -
PAT甲级 1067 Sort with Swap(0, i) (25分)简单模拟+思维处理超时
**1067 Sort with Swap(0, i) (25分)**Given any permutation of the numbers {0, 1, 2,…, N−1}, it is easy to sort them in increasing order. But what if Swap(0, *) is the ONLY operation that is allowed to use? For example, to sort {4, 0, 2, 1, 3} we may apply原创 2020-08-20 22:33:01 · 141 阅读 · 0 评论 -
PAT甲级 1059 Prime Factors (25分) 素数筛
**1059 Prime Factors (25分)**Given any positive integer N, you are supposed to find all of its prime factors, and write them in the format N = p1k1×p2k2×⋯×pmkm.Input Specification:Each input file contains one test case which原创 2020-08-15 22:06:13 · 85 阅读 · 0 评论 -
PAT甲级 1057 Stack (30分)二分更新查询
**1057 Stack (30分)**Stack is one of the most fundamental data structures, which is based on the principle of Last In First Out (LIFO). The basic operations include Push (inserting an element onto the top position) and Pop (deleting the top element). Now原创 2020-08-15 21:36:56 · 90 阅读 · 0 评论 -
PAT甲级 1055 The World‘s Richest (25分)--线段树优化查询
**1055 The World’s Richest (25分)**Forbes magazine publishes every year its list of billionaires based on the annual ranking of the world’s wealthiest people. Now you are supposed to simulate this job, but concentrate only on the people in a certain rang原创 2020-08-15 01:13:07 · 132 阅读 · 0 评论 -
PAT甲级 1049 Counting Ones (30分)--数论,根据数据性质找规律
1049 Counting Ones (30分)The task is simple: given any positive integer N, you are supposed to count the total number of 1’s in the decimal form of the integers from 1 to N. For example, given N being 12, there are five 1’s in 1, 10, 11, and 12.Input Spec原创 2020-08-13 23:55:01 · 139 阅读 · 0 评论 -
PAT甲级 1045 Favorite Color Stripe (30分)--最长上升子序列,动态规划
**1045 Favorite Color Stripe (30分)**Eva is trying to make her own color stripe out of a given one. She would like to keep only her favorite colors in her favorite order by cutting off those unwanted pieces and sewing the remaining parts together to form原创 2020-08-13 21:49:52 · 106 阅读 · 0 评论 -
PAT甲级 1044 Shopping in Mars (25分)--双指针
**1044 Shopping in Mars (25分)**Shopping in Mars is quite a different experience. The Mars people pay by chained diamonds. Each diamond has a value (in Mars dollars M$). When making the payment, the chain can be cut at any position for only once and some原创 2020-08-13 21:36:32 · 152 阅读 · 0 评论 -
PAT甲级 1043 Is It a Binary Search Tree (25分) 二叉查询树的遍历
1043 Is It a Binary Search Tree (25分)A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties:The left subtree of a node contains only nodes with keys less than the node’s key.The right subtree of a node cont原创 2020-08-13 12:10:19 · 167 阅读 · 0 评论 -
数据结构 二叉树的遍历(前序遍历,中序遍历和后序遍历)实现
给一定不带权值只有节点的二叉树,如下图首先说明二叉树各种遍历方法的顺序:1.前序遍历:根->左->右2.中序遍历:左->根->右3.后序遍历:左->右->根于是上图中3种方法遍历结果1.前序遍历:1 2 4 5 3 6 7 8 92.中序遍历:4 2 5 1 6 3 8 9 73.后序遍历:4 5 2 6 9 8 7 3 1现在用C++进行3种遍历的实现输入格式为输入一个根节点,输入对应的左右子节点,如果左/右子节点没有,输入-1表示。如上图输入数据原创 2020-08-13 10:33:28 · 1838 阅读 · 0 评论 -
PAT甲级 1033 To Fill or Not to Fill (25分)--贪心策略
**1033 To Fill or Not to Fill (25分)**With highways available, driving a car from Hangzhou to any other city is easy. But since the tank capacity of a car is limited, we have to find gas stations on the way from time to time. Different gas station may gi原创 2020-08-13 10:04:11 · 131 阅读 · 0 评论 -
PAT甲级 1039 Course List for Student (25分)--关于段错误,关闭C++同步流避免超时
1039 Course List for Student (25分)Zhejiang University has 40000 students and provides 2500 courses. Now given the student name lists of all the courses, you are supposed to output the registered course list for each student who comes for a query.Input Sp原创 2020-08-12 22:13:46 · 267 阅读 · 1 评论 -
PAT甲级 1087 All Roads Lead to Rome (30分)--迪杰斯特拉最短路两种解法(DFS暴力搜索+最短路直接优化)
**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 route with the least cost while gaining the most happiness.Input Specification:Each input file contain原创 2020-08-09 23:01:28 · 138 阅读 · 0 评论 -
PAT甲级 1026 Table Tennis (30分)大模拟
**1026 Table Tennis (30分)**A table tennis club has N tables available to the public. The tables are numbered from 1 to N. For any pair of players, if there are some tables open when they arrive, they will be assigned to the available table with the smal原创 2020-08-08 20:43:00 · 187 阅读 · 0 评论 -
PAT甲级 1020 Tree Traversals (25分)--数据结构递归处理
**1020 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.原创 2020-08-07 19:25:50 · 108 阅读 · 0 评论 -
PAT甲级 1010 Radix (25分)
1010 Radix (25分)Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The answer is yes, if 6 is a decimal number and 110 is a binary number.Now for any pair of positive integers N1 and N2, your task is to fi原创 2020-08-05 23:58:05 · 137 阅读 · 0 评论 -
PAT甲级 1003 Emergency (25分)
1003 Emergency (25分)As an emergency rescue team leader of a city, you are given a special map of your country. The map shows several scattered cities connected by some roads. Amount of rescue teams in each city and the length of each road between any pair原创 2020-08-03 23:35:27 · 114 阅读 · 0 评论