自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(146)
  • 收藏
  • 关注

原创 PAT 刷题笔记

常见专业名词:recursively 递归地traversal 遍历,横越;横断物DFS 与 BFS在DFS中关键点是递归以及回溯,在BFS中,关键点则是状态的选取和标记。DFS用递归的形式,用到了栈结构,先进后出。(根据题不同注意递归点与回溯点)BFS选取状态用队列的形式+循环,先进先出。已知中序与前序遍历重建二叉树:不断拆分节点如下代码是先...

2020-02-05 22:26:50 300

原创 自用图床

2021-05-26 18:30:28 142

原创 自用算法模板整理

1.排序:快排#include <iostream>#include <vector>using namespace std;int partition(vector<int> &a, int l, int r) { int p = a[l]; while (l < r) { while (a[r] > p && l < r) r--; if (l < r) { a[l] = a[

2021-02-06 09:45:27 179

原创 进阶实验6-3.1 红色警报 (25分)

进阶实验6-3.1 红色警报 (25分)战争中保持各个城市间的连通性非常重要。本题要求你编写一个报警程序,当失去一个城市导致国家被分裂为多个无法连通的区域时,就发出红色警报。注意:若该国本来就不完全连通,是分裂的k个区域,而失去一个城市并不改变其他城市之间的连通性,则不要发出警报。输入格式:输入在第一行给出两个整数N(0<N≤500)和M(≤5000),分别为城市个数(于是默认城市从0到N-1编号)和连接两城市的通路条数。随后M行,每行给出一条通路所连接的两个城市的编号,其间以...

2020-08-20 00:56:19 246

原创 基础实验6-2.3 拯救007 (25分) [浙大版《数据结构学习与实验指导(第2版)》]

题目连接:基础实验6-2.3 拯救007 (25分)在老电影“007之生死关头”(Live and Let Die)中有一个情节,007被毒贩抓到一个鳄鱼池中心的小岛上,他用了一种极为大胆的方法逃脱 —— 直接踩着池子里一系列鳄鱼的大脑袋跳上岸去!(据说当年替身演员被最后一条鳄鱼咬住了脚,幸好穿的是特别加厚的靴子才逃过一劫。)设鳄鱼池是长宽为100米的方形,中心坐标为 (0, 0),且东北角坐标为 (50, 50)。池心岛是以 (0, 0) 为圆心、直径15米的圆。给定池中分布的鳄鱼的坐标、以及00

2020-08-17 00:46:52 624

原创 案例6-1.3 哥尼斯堡的“七桥问题” (25分) 浙大版《数据结构学习与实验指导(第2版)》

案例6-1.3 哥尼斯堡的“七桥问题” (25分)哥尼斯堡是位于普累格河上的一座城市,它包含两个岛屿及连接它们的七座桥,如下图所示。可否走过这样的七座桥,而且每桥只走过一次?瑞士数学家欧拉(Leonhard Euler,1707—1783)最终解决了这个问题,并由此创立了拓扑学。这个问题如今可以描述为判断欧拉回路是否存在的问题。欧拉回路是指不令笔离开纸面,可画过图中每条边仅一次,且可以回到起点的一条回路。现给定一个无向图,问是否存在欧拉回路?输入格式:输入第一行给出两个正整数,分别.

2020-08-14 00:48:32 307

原创 基础实验6-2.2 汉密尔顿回路 (25分) --浙大版《数据结构学习与实验指导(第2版)》

题目连接:基础实验6-2.2 汉密尔顿回路 (25分) 著名的“汉密尔顿(Hamilton)回路问题”是要找一个能遍历图中所有顶点的简单回路(即每个顶点只访问 1 次)。本题就要求你判断任一给定的回路是否汉密尔顿回路。输入格式:首先第一行给出两个正整数:无向图中顶点数N(2<N≤200)和边数M。随后M行,每行给出一条边的两个端点,格式为“顶点1 顶点2”,其中顶点从 1 到N编号。再下一行给出一个正整数K,是待检验的回路的条数。随后K行,每行给出一条待检回路,格式为:...

2020-08-13 00:05:07 369 1

原创 基础实验8-1.2 直捣黄龙 (30分) [浙大版《数据结构学习与实验指导(第2版)》题目集]

基础实验8-1.2 直捣黄龙 (30分)本题是一部战争大片 —— 你需要从己方大本营出发,一路攻城略地杀到敌方大本营。首先时间就是生命,所以你必须选择合适的路径,以最快的速度占领敌方大本营。当这样的路径不唯一时,要求选择可以沿途解放最多城镇的路径。若这样的路径也不唯一,则选择可以有效杀伤最多敌军的路径。输入格式:输入第一行给出2个正整数N(2≤N≤200,城镇总数)和K(城镇间道路条数),以及己方大本营和敌方大本营的代号。随后N-1行,每行给出除了己方大本营外的一个城镇的代号和驻守的敌军...

2020-08-12 00:55:12 1221

原创 进阶实验8-2.1 逆散列问题 (30分) 【浙大版 数据结构学习与实验指导】

给定长度为N的散列表,处理整数最常用的散列映射是H(x)=x%N。如果我们决定用线性探测解决冲突问题,则给定一个顺序输入的整数序列后,我们可以很容易得到这些整数在散列表中的分布。例如我们将 1、2、3 顺序插入长度为 3 的散列表HT[]后,将得到HT[0]=3,HT[1]=1,HT[2]=2的结果。但是现在要求解决的是“逆散列问题”,即给定整数在散列表中的分布,问这些整数是按什么顺序插入的?输入格式:输入的第一行是正整数 N(≤1000),为散列表的长度。第二行给出了 N 个整数,...

2020-08-10 01:02:54 772

原创 PAT(甲级)2019年春季考试

7-1Sexy Primes(20分)Sexy primes are pairs of primes of the form (p,p+6), so-named since "sex" is the Latin word for "six". (Quoted fromhttp://mathworld.wolfram.com/SexyPrimes.html)Now given an integer, you are supposed to tell if it is a sexy prime....

2020-07-23 18:15:52 686

原创 7-2 Block Reversing (25分) 【PAT 甲级19年冬考】

Given a singly linked listL. Let us consider everyKnodes as ablock(if there are less thanKnodes at the end of the list, the rest of the nodes are still considered as a block). Your job is to reverse all the blocks inL. For example, givenLas 1→2→3...

2020-07-22 10:53:48 449 6

原创 7-4 Cartesian Tree (30分) 【PAT 甲级19年冬考】

ACartesian treeis a binary tree constructed from a sequence of distinct numbers. The tree is heap-ordered, and an inorder traversal returns the original sequence. For example, given the sequence { 8, 15, 3, 4, 1, 5, 12, 10, 18, 6 }, the min-heap Cartesia..

2020-07-22 10:36:48 145

原创 7-3 Summit (25分) [PAT甲级 19年冬考]

Asummit(峰会) is a meeting of heads of state or government. Arranging the rest areas for the summit is not a simple job. The ideal arrangement of one area is to invite those heads so that everyone is a direct friend of everyone.Now given a set of tentati..

2020-07-22 10:34:23 128

原创 1117 Eddington Number (25分)

British astronomer Eddington liked to ride a bike. It is said that in order to show off his skill, he has even defined an "Eddington number",E-- that is, the maximum integerEsuch that it is forEdays that one rides more thanEmiles. Eddington's ownE...

2020-07-11 00:00:47 108

原创 1133 Splitting A Linked List (25分)

Given a singly linked list, you are supposed to rearrange its elements so that all the negative values appear before all of the non-negatives, and all the values in [0, K] appear before all those greater than K. The order of the elements inside each class

2020-07-09 23:50:02 116

原创 1148 Werewolf - Simple Version (20分)

Werewolf(狼人杀) is a game in which the players are partitioned into two parties: the werewolves and the human beings. Suppose that in a game,player #1 said: "Player #2 is a werewolf."; player #2 said: "Player #3 is a human."; player #3 said: "Player #4 i

2020-07-09 01:07:00 134

原创 1132 Cut Integer (20分)

Cutting an integer means to cut a K digits lone integer Z into two integers of (K/2) digits long integers A and B. For example, after cutting Z = 167334, we have A = 167 and B = 334. It is interesting to see that Z can be devided by the product of A and...

2020-07-05 01:02:46 83

原创 1129 Recommendation System (25分)

Recommendation system predicts the preference that a user would give to an item. Now you are asked to program a very simple recommendation system that rates the user's preference by the number of times that an item has been accessed by this user.Input Sp

2020-07-05 00:38:50 134

原创 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 file contains one test case. For each case, the first

2020-07-03 00:46:04 80

原创 1109 Group Photo (25分)

Formation is very important when taking a group photo. Given the rules of formingKrows withNpeople as the following: The number of people in each row must beN/K(round down to the nearest integer), with all the extra people (if any) standing in the...

2020-07-02 00:52:21 143

原创 1105 Spiral Matrix (25分)

This time your job is to fill a sequence ofNpositive integers into aspiral matrixin non-increasing order. A spiral matrix is filled in from the first element at the upper-left corner, then move in a clockwise spiral. The matrix hasmrows andncolumns...

2020-07-01 01:27:49 103

原创 1014 Waiting in Line (30分)

Suppose a bank hasNwindows open for service. There is a yellow line in front of the windows which devides the waiting area into two parts. The rules for the customers to wait in line are:The space inside the yellow line in front of each window is enoug..

2020-06-28 01:10:20 157 1

原创 1152 Google Recruitment (20分)

In July 2004, Google posted on a giant billboard along Highway 101 in Silicon Valley (shown in the picture below) for recruitment. The content is super-simple, a URL consisting of the first 10-digit prime found in consecutive digits of the natural constant

2020-06-27 01:02:31 75

原创 1116 Come on Lets 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 the following:0、 The Champion will receive a "Mystery

2020-06-26 01:27:46 189

原创 1112 Stucked Keyboard (20分)

On a broken keyboard, some of the keys are always stucked. So when you type some sentences, the characters corresponding to those keys will appear repeatedly on screen forktimes.Now given a resulting string on screen, you are supposed to list all th...

2020-06-25 01:36:03 136

原创 1072 Gas Station (30分)

A gas station has to be built at such a location that the minimum distance between the station and any of the residential housing is as far away as possible. However it must guarantee that all the houses are in its service range.Now given the map of t...

2020-06-24 00:24:56 142

原创 1018 Public Bike Management (30分)

There is a public bike service in Hangzhou City which provides great convenience to the tourists from all over the world. One may rent a bike at any station and return it to any other stations in the city.The Public Bike Management Center (PBMC) keeps mo

2020-06-21 01:34:43 78

原创 1136 A Delayed Palindrome (20分)

Consider a positive integerNwritten in standard notation withk+1digitsa​i​​asa​k​​⋯a​1​​a​0​​with0≤a​i​​<10for allianda​k​​>0. ThenNispalindromicif and only ifa​i​​=a​k−i​​for alli. Zero is written 0 and is also palindromic by def...

2020-06-18 01:14:20 95

原创 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,Tfor the top level,Afor advance andBfor basic; the 2nd - 4th digits are the test site number, ranged from 101 to 999; the 5th - 10th digits giv...

2020-06-17 01:50:42 128

原创 1141 PAT Ranking of Institutions (25分)

After each PAT, the PAT Center will announce the ranking of institutions based on their students' performances. Now you are asked to generate the ranklist.Input Specification:Each input file contains one test case. For each case, the first line gives a

2020-06-15 00:30:58 104

原创 1124 Raffle for Weibo Followers (20分)

John got a full mark on PAT. He was so happy that he decided to hold a raffle(抽奖) for his followers on Weibo -- that is, he would select winners from every N followers who forwarded his post, and give away gifts. Now you are supposed to help him generate t

2020-06-14 00:55:29 121

原创 1108 Finding Average (20分)

The basic task is simple: givenNreal numbers, you are supposed to calculate their average. But what makes it complicated is that some of the input numbers might not be legal. Alegalinput is a real number in [−1000,1000] and is accurate up to no more th...

2020-06-13 01:00:39 100

原创 1130 Infix Expression (25分)

Given a syntax tree (binary), you are supposed to output the corresponding infix expression, with parentheses reflecting the precedences of the operators.Input Specification:Each input file contains one test case. For each case, the first line gives a

2020-06-04 01:19:20 70

原创 1155 Heap Paths (30分)

In computer science, aheapis 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 (in a max heap) or less than or equal to (in a min heap) t..

2020-06-03 00:26:55 80

原创 1114 Family Property (25分)

This time, you are supposed to help us collect the data for family-owned property. Given each person's family members, and the estate(房产)info under his/her own name, we need to know the size of each family, and the average area and number of sets of their

2020-05-29 22:31:58 103

原创 1137 Final Grading (25分)

For a student taking the online course "Data Structures" on China University MOOC (http://www.icourse163.org/), to be qualified for a certificate, he/she must first obtain no less than 200 points from the online programming assignments, and then receive a

2020-05-25 02:26:48 82

原创 1149 Dangerous Goods Packaging (25分)

When shipping goods with containers, we have to be careful not to pack some incompatible goods into the same container, or we might get ourselves in serious trouble. For example, oxidizing agent (氧化剂) must not be packed with flammable liquid (易燃液体), or it

2020-05-24 01:35:13 103

原创 1120 Friend Numbers (20分)

Two integers are called "friend numbers" if they share the same sum of their digits, and the sum is their "friend ID". For example, 123 and 51 are friend numbers since 1+2+3 = 5+1 = 6, and 6 is their friend ID. Given some numbers, you are supposed to co...

2020-05-24 00:29:02 79

原创 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 her favorite color stripe.It is said

2020-05-22 00:15:36 113

原创 1007 Maximum Subsequence Sum (25分) [DP]

Given a sequence ofKintegers {N​1​​,N​2​​, ...,N​K​​}. A continuous subsequence is defined to be {N​i​​,N​i+1​​, ...,N​j​​} where1≤i≤j≤K. The Maximum Subsequence is the continuous subsequence which has the largest sum of its elements. For exa...

2020-05-21 00:54:24 132

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除