- 博客(294)
- 收藏
- 关注
原创 【202206-3 角色授权】
大模拟,最重要的是建立每个用户和用户组关联的所有角色,这样直接查询即可,利用unordered_maputor记录。
2023-03-06 23:25:59 157
原创 【202206-2 寻宝!大冒险!】满分代码
遍历n组绿化图的树坐标,将它们作为b[0][0]对应的a[x][y],然后遍历藏宝图,如果藏宝图b[j][k]==1,查找m中对应坐标,如果没有树,说明第i组坐标不能作为可能的藏宝地点,继续下一个;如果藏宝图b[j][k]==0,查找m中对应坐标,如果有树,说明不符合,继续下一个;遍历完一遍藏宝图b之后如果flag==0说明遍历过程中没有出现不符合的点,ans++;二维数组矩阵只建立藏宝图的,绿化图的树用两个一维数组记录坐标;
2023-03-04 21:02:01 262
原创 【202209-2 何以包邮?】
dfs枚举所有情况,每本书都有选或者不选两种,不剪枝只有七十分,剩下的会超时。当前方案加上后续所有方案仍然小于x,直接return;剪枝:当前方案已经大于x,记录结果,不再继续往下选;
2023-03-02 22:54:25 168
原创 【202212-2 训练计划】满分代码
初始化所有项目的最晚开始时间为n+1,从m到1遍历,先减去自己的练习时间,同时检查,如果本项目是被别的项目依赖的,说明最晚开始时间有可能需要提前,遍历依赖于本项目的所有项目,在自己目前的最晚开始时间、依赖于本项目的所有项目的最晚开始时间-练习时间中,取最小值,就是本项目的最晚开始时间,由于【每项科目最多只依赖一项别的科目,且满足依赖科目的编号小于自己】,所以按照编号从大到小遍历一遍即可。同时检查,如果有项目的最早开始时间+练习时间>n+1,说明不能在n天内完成任务,flag=1。
2023-02-27 21:30:42 310
原创 剑指 Offer 09. 用两个栈实现队列
分别完成在队列尾部插入整数和在队列头部删除整数的功能。(若队列中没有元素,最多会对 appendTail、deleteHead 进行 10000 次调用。用两个栈实现一个队列。队列的声明如下,请实现它的两个函数。
2023-02-07 10:59:26 78
原创 1167 Cartesian Tree
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
2022-12-19 16:53:20 105
原创 1166 Summit
A(峰会) 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.
2022-12-19 16:18:30 333
原创 1165 Block Reversing
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
2022-12-18 20:23:13 336
原创 1164 Good in C
When your interviewer asks you to write "Hello World" using C, can you do as the following figure shows?
2022-12-16 15:17:41 93
原创 1163 Dijkstra Sequence
Dijkstra's algorithm is one of the very famous greedy algorithms.It is used for solving the single source shortest path problem which gives the shortest paths from one particular source vertex to all the other vertices of the given graph. It was conceived
2022-12-14 18:32:13 258
原创 1162 Postfix Expression
Given a syntax tree (binary), you are supposed to output the corresponding postfix expression, with parentheses reflecting the precedences of the operators.
2022-12-13 18:50:20 365
原创 机器学习复习博客
1、线性回归:线性回归模型详解(Linear Regression)_taoKingRead的博客-CSDN博客_线性回归模型2、线性回归梯度下降:线性回归的求解:矩阵方程和梯度下降、数学推导及NumPy实现 - 知乎 (zhihu.com)
2022-12-12 23:06:50 77
原创 1161 Merging Linked Lists
Given two singly linked listsL1=a1→a2→⋯→an−1→anandL2=b1→b2→⋯→bm−1→bm. Ifn≥2m, you are supposed to reverse and merge the shorter one into the longer one to obtain a list likea1→a2→bm→a3→a4→bm−1⋯. For example, given one list being 6→7 an
2022-12-12 11:25:04 292
原创 1160 Forever
"Forever number" is a positive integerAwithKdigits, satisfying the following constrains:the sum of all the digits ofAism;the sum of all the digits ofA+1isn; andthe greatest common divisor ofmandnis a prime number which is greater than 2.
2022-12-11 18:20:47 426
原创 1159 Structure of a Binary Tree
Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and inorder traversal sequences, a binary tree can be uniquely determined.Now given a sequence of statements about the structure of the resulting tree, you are
2022-12-10 17:57:16 488
原创 1158 Telefraud Detection
(1)输入时,记录每对打电话和接电话人的通话时长;(2)二重循环遍历所有两人组合,如果两人之间的通话时间总和不超过5分钟,记为有效通话,同时如果反过来,这组接电话的人有回电话,即时间大于零,就记这组打电话的人被回了一次电话。(3)从1到N遍历编号,如果有效通话次数大于k并且被回电话的次数不超过20%,则把这个人列为嫌疑人。(4)嫌疑人个数为0则直接输出none(5)并查集分帮派,二重循环遍历所有嫌疑人的两人组合,如果两个人互相打过电话,则merge。(6)遍历所有嫌疑人,以嫌疑人并查集中
2022-12-09 15:17:48 404
原创 1157 Anniversary
Zhejiang University is about to celebrate her 122th anniversary in 2019. To prepare for the celebration, the alumni association (校友会) has gathered the ID's of all her alumni. Now your job is to write a program to count the number of alumni among all the pe
2022-12-09 10:50:21 128
原创 1156 Sexy Primes
Sexy primes are pairs of primes of the form (p, p+6), so-named since "sex" is the Latin word for "six". (Quoted from http://mathworld.wolfram.com/SexyPrimes.html)Now given an integer, you are supposed to tell if it is a sexy prime.Each input file contains
2022-12-08 12:04:03 485
原创 1155 Heap Paths
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 (in a max heap) or less than or equal to (in a min heap) t
2022-12-07 14:03:39 421
原创 1154 Vertex Coloring
A proper vertex coloring is a labeling of the graph's vertices with colors such that no two vertices sharing the same edge have the same color. A coloring using at most k colors is called a (proper) k-coloring.Now you are supposed to tell if a given colori
2022-12-07 13:13:07 208
原创 1153 Decode Registration Card of PAT
A registration card number of PAT consists of 4 parts:Now given a set of registration card numbers and the scores of the card owners, you are supposed to output the various statistics according to the given queries.Each input file contains one test case. F
2022-12-06 12:06:27 120
原创 1152 Google Recruitment
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
2022-12-05 11:19:44 75
原创 1151 LCA in a Binary Tree
The lowest common ancestor (LCA) of two nodes U and V in a tree is the deepest node that has both U and V as descendants.Given any two nodes in a binary tree, you are supposed to find their LCA.Each input file contains one test case. For each case, the fir
2022-12-05 01:16:20 206
原创 1150 Travelling Salesman Problem
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 returns to the origin city?" It is an NP-hard problem in com
2022-12-03 13:03:41 80
原创 1149 Dangerous Goods Packaging
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
2022-12-03 10:46:59 441
原创 1148 Werewolf - Simple Version
Werewolf(狼人杀) is a game in which the players are partitioned into two parties: the werewolves and the human beings. Suppose that in a game,
2022-12-02 14:52:58 364
原创 1147 Heaps
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
2022-12-01 10:30:24 324
原创 1146 Topological Order
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.Each input file contains one test c
2022-12-01 09:26:26 59
原创 1145 Hashing - Average Search Time
The task of this problem is simple: insert a sequence of distinct positive integers into a hash table first. Then try to find another sequence of integer keys from the table and output the average search time (the number of comparisons made to find whether
2022-11-30 21:42:35 118
原创 1144 The Missing Number
Given N integers, you are supposed to find the smallest positive integer that is NOT in the given list.
2022-11-30 19:57:59 142
原创 1143 Lowest Common Ancestor
因为输入的是前序遍历,根据二叉搜索树定义,可以根据前序序列建树,同时记录每个节点的父节点,根节点的父节点为NULL,map记录出现的节点,输入u,v后先判断是否存在,如果都存在则通过r->fa找到父节点,并分别记录从u、v到达根节点的路径,然后将两条路径进行对比,第一个相同的值就是LCA。
2022-11-29 22:31:53 389
原创 1142 Maximal Clique
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 from https://en.wikipedia.org/wiki
2022-11-27 19:55:55 272
原创 1141 PAT Ranking of Institutions
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.
2022-11-26 19:33:15 319
原创 1140 Look-and-say Sequence
Look-and-say sequence is a sequence of integers as the following:
2022-11-25 16:16:24 366
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人