- 博客(16)
- 收藏
- 关注
原创 PriorityQueue自定义大顶堆(普通+Map.Entry)
堆是一种基于完全二叉树的优先队列,Java 中通过 PriorityQueue 实现,底层是数组,但逻辑上是二叉树结构,包含小顶堆(默认:堆顶为最小元素)和大顶堆(堆顶为最大元素)两种。近期在刷算法题时复习到堆,“TopK 高频元素” 是经典的堆应用场景,而理解大顶堆的排序逻辑是解决这道题的核心。本文主要讲了大顶堆的自定义排序包括普通的排序和Map的。1.核心需求:统计数组中数字的出现次数(存储在 Map 中),按 “次数” 降序排序,堆顶是 “次数最多的数字 + 次数” 键值对。写法 2:匿名内部类。
2026-01-08 17:04:49
87
原创 二分查找的区间开闭问题
如果 l 和 r 都是接近2147483647的大整数(比如l=2147483646,r=2147483647),那么l + r = 4294967293,远超int的最大值,会触发整数溢出:溢出后l + r变成负数(如4294967293溢出后是-3);区间 [l, r) 表示:搜索范围包含下标 l 的元素,但不包含 r 的元素,即 l ≤ 目标元素 < r。刚开始学习经常使用mid = (l + r) / 2,但会触发整数溢出,而 ((r - l) >> 1) + l 是行业内的标准写法。
2026-01-03 21:44:11
353
原创 事件驱动复习6
Sometimes functions are not members of a class called global functions (全局函数)Function Definitions with Mutiple Paramenters:function prototype (declaration): int test ( int );function header: int test ( int b ) ;signature: test ( int );cout&
2022-05-18 19:35:57
241
原创 事件驱动复习4、5
Pseudocode ( or “fake” code ) is an artifical and informal language that helps you develop algorithms. 伪代码概念(1)normally describes only executable statements通常仅描述可执行语句(2)Declarations are not executable statements声明不是可执行语句sequrntial execution:(顺序执行)st
2022-05-18 10:48:21
268
原创 事件驱动复习3
Generally, data members should be declared private and member functions should be declared public.set functions also called mutatorsget functions also called accessorsclasses often provide public member functions to allow clients of the class to set or
2022-05-17 20:44:13
233
原创 事件驱动复习1
Three types of instructions :1.Machine languages2.Assembly languages3.High-level languages
2022-05-14 10:23:25
238
原创 事件驱动复习2
A single-line comment //Indent 缩进backslash \ 反斜杠stream extraction operator (using namespace std)standard input stream (std::cin)stream manipulator (std::endl)Fundamental types:int , double , charAdding Integers:1.A variable name is any valid iden
2022-05-14 10:22:52
187
原创 操作系统复习五
ch5 Process SynchronisationMotivation:1.Maintaining data consistency requires mechanisms to ensure the orderly execution of cooperating processes.2.Suppose that we want to provide a solution to the consumer-producer problem that fills all buffer slots.
2021-12-15 09:48:41
657
原创 操作系统复习四
ch4 DeadlockDeadlock:A set of blocked processes each holding a resource and waiting to acquire a resource held by another process in the set.–The system model for deadlocks first requires a process request a resource, then use the resource, and finally
2021-12-14 17:45:22
305
原创 操作系统复习三
Week7磁盘调度What is a Disk?1.A disk is a magnetic storage device which has a number of platters( or surfaces ).2.The entire assembly of platters rotates as a unit at high speeds (typically 5000-10000 RPM for a fixed disk. )3.The surface of each platter i
2021-12-13 17:14:18
323
原创 操作系统复习二
Week5_Lec 1Basic Concepts - Typical Program Behavior–Maximun CPU utilization obtained with multiprogramming–CPU-I/O Burst Cycle: Process execution consists of a cycle of CPU excution and I/O waitCPU Scheduling: Part 1–Selects from among the processes
2021-12-13 10:04:09
478
原创 True Liars POJ - 1417
True Liars POJ - 1417题目:(带权并查集+01背包)After having drifted about in a small boat for a couple of days, Akira Crusoe Maeda was finally cast ashore on a foggy island. Though he was exhausted and despaired, he was still fortunate to remember a legend of the
2021-11-07 21:10:12
357
原创 01背包问题plus
01背包问题plus使用DP时,当第二维体积范围较大时,正常的01背包会超时。因此第二种写法(价值比较小的情况下),我们将dp的对象由体积换成价值。若价值的数据范围也很大,那么此种方法也不适合了。定义dp[i+1][j]为在前i个物品中挑出价值总和为j所需要的最小体积,不存在时则为INF,由前0个物品没有可选的,所以初始化dp[0][0]=0;即初始化时:------------- 1.dp[i][j]=INF;------------- 2.dp[0][0]=0;题目(仅举例)代码:
2021-10-16 20:52:31
313
原创 Bakry and Partitioning
题目 C. Bakry and PartitioningBakry and PartitioningBakry faced a problem, but since he’s lazy to solve it, he asks for your help.You are given a tree of n nodes, the i-th node has value ai assigned to it for each i from 1 to n. As a reminder, a tree on
2021-10-09 21:04:55
283
原创 SDUT 2021 Summer Individual Contest - 6补题
Yet Another Sorting Problem题目:给出一个长度为N+M的序列p,它是(1,2…,N+M)的一个置换。p的第i项是pi。你可以做以下任何次数的操作。在1到N(包括)之间选择一个整数n,在1到M(包括)之间选择一个整数m。然后,交换 pn和pN+m。找出将p按升序排序所需的最少操作数。我们可以证明,有可能对 p 在这个问题的约束条件下,可以按升序排序。限制条件输入的所有数值都是整数。1 ≤ N , M ≤ 10 5 1 ≤ p i ≤ N + M p 是一个 (
2021-08-11 19:22:42
379
1
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅