- 博客(19)
- 收藏
- 关注
原创 关于二叉树的三种遍历的迭代写法
前几天在leetcode上看到一位大佬写的二叉树的迭代写法,博主觉得非常好记实用便记录下来。struct TreeNode{TreeNode *right,*left;int val;}先序写法(入栈顺序为右左中)vector<int> preorder(TreeNode * root){vector<int>res;stack<TreeNode*> stif(root!=nullptr) st.push(root);while(!call.empt
2020-05-15 11:40:36
373
原创 1150 Travelling Salesman Problem (25分)
The “travelling salesman problem” asks the following question: “Given a list of cities and the distances between each pair of cities, what is the shortest possible route that visits each city and retu...
2020-04-07 14:40:15
144
原创 1147 Heaps (30分)
In computer science, a heap is a specialized tree-based data structure that satisfies the heap property: if P is a parent node of C, then the key (the value) of P is either greater than or equal to (i...
2020-04-07 11:07:34
146
原创 PAT 甲级 1142 Maximal Clique (25分)
A clique is a subset of vertices of an undirected graph such that every two distinct vertices in the clique are adjacent. A maximal clique is a clique that cannot be extended by including one more adj...
2020-04-06 12:09:05
158
原创 PAT 甲级1127 ZigZagging on a Tree (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. And it is a simple stand...
2020-04-03 19:24:06
154
原创 PAT 甲级1121 Damn Single (25分)
“Damn Single (单身狗)” is the Chinese nickname for someone who is being single. You are supposed to find those who are alone in a big party, so they can be taken care of.Input Specification:Each input ...
2020-04-03 10:48:50
127
原创 PAT 甲级1116 Come on! Let's C (20分)
“Let’s C” is a popular and fun programming contest hosted by the College of Computer Science and Technology, Zhejiang University. Since the idea of the contest is for fun, the award rules are funny as...
2020-04-01 20:21:23
139
原创 PAT甲级1113 Integer Set Partition (25分)
Given a set of N (>1) positive integers, you are supposed to partition them into two disjoint sets A1 and A2 of n1 and n2numbers, respectively. Let S1and S2 denote the sums of all the number...
2020-04-01 13:46:50
135
原创 PAT 甲级 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 from one root supplier, everyone on the...
2020-03-30 19:41:58
166
原创 1092 To Buy or Not to Buy (20point(s))
Eva would like to make a string of beads with her favorite colors so she went to a small shop to buy some beads. There were many colorful strings of beads. However the owner of the shop would only sel...
2020-03-18 10:50:38
111
原创 PAT甲级 1084 Broken Keyboard (20point(s))
On a broken keyboard, some of the keys are worn out. So when you type some sentences, the characters corresponding to those keys will not appear on screen.Now given a string that you are supposed to ...
2020-03-14 14:29:20
245
原创 PAT甲级1083 List Grades (25point(s))
Given a list of N student records with name, ID and grade. You are supposed to sort the records with respect to the grade in non-increasing order, and output those student records of which the grades ...
2020-03-14 12:44:04
143
原创 PAT甲级 1062 Talent and Virtue (25point(s))
About 900 years ago, a Chinese philosopher Sima Guang wrote a history book in which he talked about people’s talent and virtue. According to his theory, a man being outstanding in both talent and virt...
2020-03-03 17:48:41
213
原创 PAT甲级 1055 The World's Richest (25point(s))
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 peopl...
2020-03-01 22:43:39
132
原创 pat甲级 1053 Path of Equal Weight (30point(s))
Given a non-empty tree with root R, and with weight Wiassigned to each tree node Ti . The weight of a path from R to L is defined to be the sum of the weights of all the nodes along the path from ...
2020-03-01 16:54:09
163
原创 PAT甲级 1048 Find Coins (25point(s))
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,...
2020-02-29 17:01:14
177
原创 1039 Course List for Student (25point(s))
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 ...
2020-02-26 17:19:38
125
原创 PTA甲级 1036 Boys vs Girls (25point(s))
This time you are asked to tell the difference between the lowest grade of all the male students and the highest grade of all the female students.Input Specification:Each input file contains one tes...
2020-02-25 22:18:10
374
原创 PAT甲级 1035 Password (20point(s))
To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem is that there are always some confusing passwords since it is hard to distinguish 1 (one) from l (L ...
2020-02-25 17:43:57
148
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人