c++
「已注销」
这个作者很懒,什么都没留下…
展开
-
自用算法模板整理
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 · 210 阅读 · 0 评论 -
基础实验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 · 395 阅读 · 1 评论 -
基础实验8-1.2 直捣黄龙 (30分) [浙大版《数据结构学习与实验指导(第2版)》题目集]
基础实验8-1.2 直捣黄龙 (30分)本题是一部战争大片 —— 你需要从己方大本营出发,一路攻城略地杀到敌方大本营。首先时间就是生命,所以你必须选择合适的路径,以最快的速度占领敌方大本营。当这样的路径不唯一时,要求选择可以沿途解放最多城镇的路径。若这样的路径也不唯一,则选择可以有效杀伤最多敌军的路径。输入格式:输入第一行给出2个正整数N(2≤N≤200,城镇总数)和K(城镇间道路条数),以及己方大本营和敌方大本营的代号。随后N-1行,每行给出除了己方大本营外的一个城镇的代号和驻守的敌军...原创 2020-08-12 00:55:12 · 1289 阅读 · 0 评论 -
进阶实验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 · 823 阅读 · 0 评论 -
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 · 764 阅读 · 0 评论 -
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 · 492 阅读 · 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 · 163 阅读 · 0 评论 -
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 · 157 阅读 · 0 评论 -
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 · 126 阅读 · 0 评论 -
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 · 135 阅读 · 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. 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 · 158 阅读 · 0 评论 -
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 · 108 阅读 · 0 评论 -
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 · 150 阅读 · 0 评论 -
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 · 101 阅读 · 0 评论 -
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 · 161 阅读 · 0 评论 -
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 · 119 阅读 · 0 评论 -
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 · 185 阅读 · 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 · 103 阅读 · 0 评论 -
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 · 207 阅读 · 0 评论 -
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 · 157 阅读 · 0 评论 -
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 · 160 阅读 · 0 评论 -
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 · 97 阅读 · 0 评论 -
1136 A Delayed Palindrome (20分)
Consider a positive integerNwritten in standard notation withk+1digitsaiasak⋯a1a0with0≤ai<10for alliandak>0. ThenNispalindromicif and only ifai=ak−ifor alli. Zero is written 0 and is also palindromic by def...原创 2020-06-18 01:14:20 · 117 阅读 · 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,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 · 149 阅读 · 0 评论 -
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 · 127 阅读 · 0 评论 -
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 · 136 阅读 · 0 评论 -
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 · 121 阅读 · 0 评论 -
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 · 89 阅读 · 0 评论 -
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 · 102 阅读 · 0 评论 -
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 · 120 阅读 · 0 评论 -
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 · 100 阅读 · 0 评论 -
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 · 129 阅读 · 0 评论 -
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 · 98 阅读 · 0 评论 -
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 · 128 阅读 · 0 评论 -
1007 Maximum Subsequence Sum (25分) [DP]
Given a sequence ofKintegers {N1,N2, ...,NK}. A continuous subsequence is defined to be {Ni,Ni+1, ...,Nj} 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 · 151 阅读 · 0 评论 -
1139 First Contact (30分)
Unlike in nowadays, the way that boys and girls expressing their feelings of love was quite subtle in the early years. When a boy A had a crush on a girl B, he would usually not contact her directly in the first place. Instead, he might ask another boy ...原创 2020-05-16 00:18:09 · 258 阅读 · 0 评论 -
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 starting position of you...原创 2020-05-15 00:43:45 · 184 阅读 · 0 评论 -
1019 General Palindromic Number (20分)
A number that will be the same when it is written forwards or backwards is known as aPalindromic Number. For example, 1234321 is a palindromic number. All single digit numbers are palindromic numbers.Although palindromic numbers are most often considere.原创 2020-05-11 23:41:05 · 108 阅读 · 0 评论 -
1142 Maximal Clique (25分)
Acliqueis a subset of vertices of an undirected graph such that every two distinct vertices in the clique are adjacent. Amaximal cliqueis a clique that cannot be extended by including one more adjacent vertex. (Quoted fromhttps://en.wikipedia.org/wiki...原创 2020-05-11 00:45:58 · 149 阅读 · 0 评论 -
1146 Topological Order (25分)[拓扑序列]
This is a problem given in the Graduate Entrance Exam in 2018: Which of the following is NOT a topological order obtained from the given directed graph? Now you are supposed to write a program to test each of the options.Input Specification:Each i...原创 2020-05-10 00:55:13 · 111 阅读 · 0 评论