Range Minimum Query and Lowest Common Ancestor(RMQ和LCA 找个时间翻译下)

手把手教你用Verilog实现AT24C64的I2C读写(附完整仿真流程) 本文详细介绍了如何使用Verilog HDL设计AT24C64 EEPROM的I2C控制器,并配合ModelSim完成完整的仿真验证流程。内容涵盖I2C协议解析、Verilog状态机设计、AT24C64读写操作实现,以及仿真波形分析和调试技巧,为FPGA开发者提供了一套完整的EEPROM控制解决方案。 阅读详情
 Introduction
 Notations
 Range Minimum Query (RMQ)
     Trivial algorithms for RMQ
     A <O(N), O(sqrt(N))> solution
     Sparse Table (ST) algorithm
     Segment Trees
 Lowest Common Ancestor (LCA)
     A <O(N), O(sqrt(N))> solution
     Another easy solution in <O(N logN, O(logN)>
     Reduction from LCA to RMQ
 From RMQ to LCA
 An <O(N), O(1)> algorithm for the restricted RMQ
 Conclusion 

Introduction
The problem of finding the Lowest Common Ancestor (LCA) of a pair of nodes in a rooted tree has been studied more carefully in the second part of the 20th century and now is fairly basic in algorithmic graph theory. This problem is interesting not only for the tricky algorithms that can be used to solve it, but for its numerous applications in string processing and computational biology, for example, where LCA is used with suffix trees or other tree-like structures. Harel and Tarjan were the first to study this problem more attentively and they showed that after linear preprocessing of the input tree LCA, queries can be answered in constant time. Their work has since been extended, and this tutorial will present many interesting approaches that can be used in other kinds of problems as well. 

Let's consider a less abstract example of LCA: the tree of life. It's a well-known fact that the current habitants of Earth evolved from other species. This evolving structure can be represented as a tree, in which nodes represent species, and the sons of some node represent the directly evolved species. Now species with similar characteristics are divided into groups. By finding the LCA of some nodes in this tree we can actually find the common parent of two species, and we can determine that the similar characteristics they share are inherited from that parent. 

Range Minimum Query (RMQ) is used on arrays to find the position of an element with the minimum value between two specified indices. We will see later that the LCA problem can be reduced to a restricted version of an RMQ problem, in which consecutive array elements differ by exactly 1. 

However, RMQs are not only used with LCA. They have an important role in string preprocessing, where they are used with suffix arrays (a new data structure that supports string searches almost as fast as suffix trees, but uses less memory and less coding effort). 

In this tutorial we will first talk about RMQ. We will present many approaches that solve the problem -- some slower but easier to code, and others faster. In the second part we will talk about the strong relation between LCA and RMQ. First we will review two easy approaches for LCA that don't use RMQ; then show that the RMQ and LCA problems are equivalent; and, at the end, we'll look at how the RMQ problem can be reduced to its restricted version, as well as show a fast algorithm for this particular case. 

Notations
Suppose that an algorithm has preprocessing time f(n) and query time g(n). The notation for the overall complexity for the algorithm is <f(n), g(n)>. 

We will note the position of the element with the minimum value in some array A between indices i and j with RMQA(i, j). 

The furthest node from the root that is an ancestor of both u and v in some rooted  tree T is LCAT(u, v). 

Range Minimum Query(RMQ)
Given an array A[0, N-1] find the position of  the element with the minimum value between two given indices. 



Trivial algorithms for RMQ
For every pair of indices  (i, j) store the value of  RMQA(i, j) in a table  M[0, N-1][0, N-1]. Trivial computation will lead us to an  <O(N3), O(1)> complexity. However, by using an easy dynamic programming approach we can reduce the complexity to  <O(N2), O(1)>. The preprocessing function will look something like this:
  void process1(int M[MAXN][MAXN], int A[MAXN], int N)
  {
      int i, j;
      for (i =0; i < N; i++)
          M[i][i] = i;
      for (i = 0; i < N; i++)
          for (j = i + 1; j < N; j++)
              if (A[M[i][j - 1]] < A[j])
                  M[i][j] = M[i][j - 1];
              else
                  M[i][j] = j;
  }
This trivial algorithm is quite slow and uses  O(N2) memory, so it won't work for large cases. 

An <O(N), O(sqrt(N))> solution
An interesting idea is to split the vector in  sqrt(N) pieces. We will keep in a vector  M[0, sqrt(N)-1] the position for the minimum value for each section.  M can be easily preprocessed in  O(N). Here is an example: 

Now let's see how can we compute  RMQA(i, j). The idea is to get the overall minimum from the  sqrt(N) sections that lie inside the interval, and from the end and the beginning of the first and the last sections that intersect the bounds of the interval. To get  RMQA(2,7) in the above example we should compare  A[2],  A[M[1]],  A[6] and  A[7] and get the position of the minimum value. It's easy to see that this algorithm doesn't make more than  3 * sqrt(N) operations per query. 

The main advantages of this approach are that is to quick to code (a plus for TopCoder-style competitions) and that you can adapt it to the dynamic version of the problem (where you can change the elements of the array between queries). 

Sparse Table (ST) algorithm
A better approach is to preprocess  RMQ for sub arrays of length  2k using dynamic programming. We will keep an array  M[0, N-1][0, logN] where  M[i][j] is the index of the minimum value in the sub array starting at  i having length  2j. Here is an example: 



For computing  M[i][j] we must search for the minimum value in the first and second half of the interval. It's obvious that the small pieces have  2j - 1 length, so the recurrence is: 



The preprocessing function will look something like this:
  void process2(int M[MAXN][LOGMAXN], int A[MAXN], int N)
  {
      int i, j;
   
  //initialize M for the intervals with length 1
      for (i = 0; i < N; i++)
          M[i][0] = i;
  //compute values from smaller to bigger intervals
      for (j = 1; 1 << j <= N; j++)
          for (i = 0; i + (1 << j) - 1 < N; i++)
              if (A[M[i][j - 1]] < A[M[i + (1 << (j - 1))][j - 1]])
                  M[i][j] = M[i][j - 1];
              else
                  M[i][j] = M[i + (1 << (j - 1))][j - 1];
  }  
Once we have these values preprocessed, let's show how we can use them to calculate  RMQA(i, j). The idea is to select two blocks that entirely cover the interval  [i..j] and  find the minimum between them. Let  k = [log(j - i + 1)]. For computing  RMQA(i, j) we can use the following formula: 



So, the overall complexity of the algorithm is  <O(N logN), O(1)>. 

Segment trees
For solving the RMQ problem we can also use segment trees. A segment tree is a heap-like data structure that can be used for making update/query operations upon array intervals in logarithmical time. We define the segment tree for the interval  [i, j] in the following recursive manner:
  • the first node will hold the information for the interval [i, j]
  • if i<j the left and right son will hold the information for the intervals [i, (i+j)/2] and [(i+j)/2+1, j]
Notice that the height of a segment tree for an interval with  N elements is  [logN] + 1. Here is how a segment tree for the interval  [0, 9] would look like: 



The segment tree has the same structure as a heap, so if we have a node numbered  x that is not a leaf the left son of  x is  2*x and the right son  2*x+1. 

For solving the RMQ problem using segment trees we should use an array  M[1, 2 * 2[logN] + 1] where  M[i] holds the minimum value position in the interval assigned to node  i. At the beginning all elements in  M should be  -1. The tree should be initialized with the following function ( b and  e are the bounds of the current interval): 

  void initialize(intnode, int b, int e, int M[MAXIND], int A[MAXN], int N)
  {
      if (b == e)
          M[node] = b;
      else
       {
  //compute the values in the left and right subtrees
          initialize(2 * node, b, (b + e) / 2, M, A, N);
          initialize(2 * node + 1, (b + e) / 2 + 1, e, M, A, N);
  //search for the minimum value in the first and 
  //second half of the interval
          if (A[M[2 * node]] <= A[M[2 * node + 1]])
              M[node] = M[2 * node];
          else
              M[node] = M[2 * node + 1]; 
      }
  } 
The function above reflects the way the tree is constructed. When calculating the minimum position for some interval we should look at the values of the sons. You should call the function with  node = 1,  b = 0 and  e  = N-1. 

We can now start making queries. If we want to find the position of the minimum value in some interval  [i, j] we should use the next easy function:
  int query(int node, int b, int e, int M[MAXIND], int A[MAXN], int i, int j)
  {
      int p1, p2;

  //if the current interval doesn't intersect //the query interval return -1     if (i > e || j < b)         return -1;   //if the current interval is included in //the query interval return M[node]     if (b >= i && e <= j)         return M[node];   //compute the minimum position in the //left and right part of the interval     p1 = query(2 * node, b, (b + e) / 2, M, A, i, j);     p2 = query(2 * node + 1, (b + e) / 2 + 1, e, M, A, i, j);   //return the position where the overall //minimum is     if (p1 == -1)         return M[node] = p2;    if (p2 == -1)         return M[node] = p1;     if (A[p1] <= A[p2])         return M[node] = p1;     return M[node] = p2;

}
You should call this function with  node = 1,  b = 0 and  e = N - 1, because the interval assigned to the first node is  [0, N-1]. 

It's easy to see that any query is done in  O(log N). Notice that we stop when we reach completely in/out intervals, so our path in the tree should split only one time. 

Using segment trees we get an  <O(N), O(logN)> algorithm. Segment trees are very powerful, not only because they can be used for RMQ. They are a very flexible data structure, can solve even the dynamic version of RMQ problem, and have numerous applications in range searching problems. 

Lowest Common Ancestor (LCA)
Given a rooted tree  T and two nodes  u and  v, find the furthest node from the root that is an ancestor for both  u and  v. Here is an example (the root of the tree will be node 1 for all examples in this editorial): 



An <O(N), O(sqrt(N))> solution
Dividing our input into equal-sized parts proves to be an interesting way to solve the RMQ problem. This method can be adapted for the LCA problem as well. The idea is to split the tree in  sqrt(H) parts, were  H is the height of the tree. Thus, the first section will contain the levels numbered from  0 to sqrt(H) - 1, the second will contain the levels numbered from  sqrt(H) to 2 * sqrt(H) - 1, and so on. Here is how the tree in the example should be divided: 



Now, for each node, we should know the ancestor that is situated on the last level of the upper next section. We will preprocess this values in an array  P[1, MAXN]. Here is how P should look like for the tree in the example (for simplity, for every node  i in the first section let  P[i] = 1): 



Notice that for the nodes situated on the levels that are the first ones in some sections,  P[i] = T[i]. We can preprocess  P using a depth first search ( T[i] is the father of node  i in the tree,  nr is  [sqrt(H)] and  L[i] is the level of the node  i):
  void dfs(int node, int T[MAXN], int N, int P[MAXN], int L[MAXN], int nr)  {
      int k;
   
  //if node is situated in the first 
  //section then P[node] = 1
  //if node is situated at the beginning
  //of some section then P[node] = T[node]
  //if none of those two cases occurs, then 
  //P[node] = P[T[node]]
      if (L[node] < nr)
          P[node] = 1;
      else
          if(!(L[node] % nr))
              P[node] = T[node];
          else
              P[node] = P[T[node]];
   
     for each son k of node
         dfs(k, T, N, P, L, nr);
  }
Now, we can easily make queries. For finding  LCA(x, y) we we will first find in what section it lays, and then trivially compute it. Here is the code:
  int LCA(int T[MAXN], int P[MAXN], int L[MAXN], int x, int y)
  {
  //as long as the node in the next section of 
  //x and y is not one common ancestor
  //we get the node situated on the smaller 
  //lever closer
      while (P[x] != P[y])
          if (L[x] > L[y])
             x = P[x];
          else
     	       y = P[y];
           
  //now they are in the same section, so we trivially compute the LCA
      while (x != y)
          if (L[x] > L[y])
             x = T[x];
          else
             y = T[y];
      return x;
  }
This function makes at most  2 * sqrt(H) operations. Using this approach we get an  <O(N), O(sqrt(H))> algorithm, where  H is the height of the tree. In the worst case  H = N, so the overall complexity is  <O(N), O(sqrt(N))>. The main advantage of this algorithm is quick coding (an average Division 1 coder shouldn't need more than 15 minutes to code it).

Another easy solution in <O(N logN, O(logN)>
If we need a faster solution for this problem we could use dynamic programming. First, let's compute a table P[1,N][1,logN] where P[i][j] is the 2 j-th ancestor of i. For computing this value we may use the following recursion: 



The preprocessing function should look like this:
  void process3(int N, int T[MAXN], int P[MAXN][LOGMAXN])
  {
      int i, j;
   
  //we initialize every element in P with -1
      for (i = 0; i < N; i++)
          for (j = 0; 1 << j < N; j++)
              P[i][j] = -1;
   
  //the first ancestor of every node i is T[i]
      for (i = 0; i < N; i++)
          P[i][0] = T[i];
   
  //bottom up dynamic programing
      for (j = 1; 1 << j < N; j++)
         for (i = 0; i < N; i++)
             if (P[i][j - 1] != -1)
                 P[i][j] = P[P[i][j - 1]][j - 1];
  }
  
This takes  O(N logN) time and space. Now let's see how we can make queries. Let  L[i] be the level of node  i in the tree. We must observe that if  p and  q are on the same level in the tree we can compute  LCA(p, q) using a meta-binary search. So, for every power  j of  2 (between  log(L[p]) and  0, in descending order), if  P[p][j] != P[q][j] then we know that LCA(p, q) is on a higher level and we will continue searching for  LCA(p = P[p][j], q = P[q][j]). At the end, both  p and  q will have the same father, so return  T[p]. Let's see what happens if  L[p] != L[q]. Assume, without loss of generality, that  L[p] < L[q]. We can use the same meta-binary search  for finding the ancestor of  p situated on the same level with  q, and then we can compute the  LCA  as described below. Here is how the query function should look:
  int query(int N, int P[MAXN][LOGMAXN], int T[MAXN], 
  int L[MAXN], int p, int q)
  {
      int tmp, log, i;
   
  //if p is situated on a higher level than q then we swap them
      if (L[p] < L[q])
          tmp = p, p = q, q = tmp;
  
  //we compute the value of [log(L[p)]
      for (log = 1; 1 << log <= L[p]; log++);
      log--;
   
  //we find the ancestor of node p situated on the same level
  //with q using the values in P
      for (i = log; i >= 0; i--)
          if (L[p] - (1 << i) >= L[q])
              p = P[p][i];
   
      if (p == q)
          return p;
   
  //we compute LCA(p, q) using the values in P
      for (i = log; i >= 0; i--)
          if (P[p][i] != -1 && P[p][i] != P[q][i])
              p = P[p][i], q = P[q][i];
   
      return T[p];
  }
Now, we can see that this function makes at most  2 * log(H) operations, where  H is the height of the tree. In the worst case  H = N, so the overall complexity of this algorithm is <O(N logN), O(logN)>. This solution is easy to code too, and it's faster than the previous one. 

Reduction from LCA to RMQ
Now, let's show how we can use RMQ for computing LCA queries. Actually, we will reduce the LCA problem to RMQ in linear time, so every algorithm that solves the RMQ problem will solve the LCA problem too. Let's show how this reduction can be done using an example: 




click to enlarge image


Notice that  LCAT(u, v) is the closest node from the root encountered between the visits of  u and  v during a depth first search of  T. So, we can consider all nodes between any two indices of  u and  v in the Euler Tour of the tree and then find the node situated on the smallest level between them. For this, we must build three arrays:
  • E[1, 2*N-1] - the nodes visited in an Euler Tour of T; E[i] is the label of i-th visited node in the tour
  • L[1, 2*N-1] - the levels of the nodes visited in the Euler Tour; L[i] is the level of node E[i]
  • H[1, N] - H[i] is the index of the first occurrence of node i in E (any occurrence would be good, so it's not bad if we consider the first one)
Assume that  H[u] < H[v] (otherwise you must swap  u and  v). It's easy to see that the nodes between the first occurrence of  u and the first occurrence of  v are  E[H[u]...H[v]]. Now, we must find the node situated on the smallest level. For this, we can use  RMQ. So,  LCAT(u, v) = E[RMQL(H[u], H[v])] (remember that RMQ returns the index). Here is how  E,  Land  H should look for the example: 


click to enlarge image


Notice that consecutive elements in L differ by exactly 1. 

From RMQ to LCA
We have shown that the LCA problem can be reduced to RMQ in linear time. Here we will show how we can reduce the RMQ problem to LCA. This means that we actually can reduce the general RMQ to the restricted version of the problem (where consecutive elements in the array differ by exactly 1). For this we should use cartesian trees. 

A Cartesian Tree of an array  A[0, N - 1] is a binary tree  C(A)  whose root is a minimum element of  A, labeled with the position  i of this minimum. The left child of the root is the Cartesian Tree of  A[0, i - 1] if  i > 0, otherwise there's no child. The right child is defined similary for  A[i + 1, N - 1]. Note that the Cartesian Tree is not necessarily unique if  Acontains equal elements. In this tutorial the first appearance of the minimum value will be used, thus the Cartesian Tree will be unique.  It's easy to see now that  RMQA(i, j) = LCAC(i, j). 

Here is an example: 





Now we only have to compute  C(A) in linear time. This can be done using a stack. At the beginning the stack is empty. We will then insert the elements of  A in the stack. At the  i-th step  A[i] will be added next to the last element in the stack that has a smaller or equal value to  A[i], and all the greater elements will be removed. The element that was in the stack on the position of  A[i] before the insertion was done will become the left son of  i, and  A[i] will become the right son of the smaller element behind him. At every step the first element in the stack is the root of the cartesian tree. It's easier to build the tree if the stack will hold the indexes of the elements, and not their value. 

Here is how the stack will look at each step for the example above: 

Step Stack Modifications made in the tree
0 0 0 is the only node in the tree.
1 0 1 1 is added at the end of the stack. Now, 1 is the right son of 0.
2 0 2 2 is added next to 0, and 1 is removed (A[2] < A[1]). Now, 2 is the right son of 0 and the left son of 2 is 1.
3 3 A[3] is the smallest element in the vector so far, so all elements in the stack will be removed and 3 will become the root of the tree. The left child of 3 is 0.
4 3 4 4 is added next to 3, and the right son of 3 is 4.
5 3 4 5 5 is added next to 4, and the right son of 4 is 5.
6 3 4 5 6 6 is added next to 5, and the right son of 5 is 6.
7 3 4 5 6 7 7 is added next to 6, and the right son of 6 is 7.
8 3 8 8 is added next to 3, and all greater elements are removed. 8 is now the right child of 3 and the left child of 8 is 4.
9 3 8 9 9 is added next to 8, and the right son of 8 is 9.

Note that every element in  A is only added once and removed at most once, so the complexity of this algorithm is  O(N). Here is how the tree-processing function will look:
  void computeTree(int A[MAXN], int N, int T[MAXN])

{     int st[MAXN], i, k, top = -1;   //we start with an empty stack //at step i we insert A[i] in the stack     for (i = 0; i < N; i++)     { //compute the position of the first element that is //equal or smaller than A[i]         k = top;         while (k >= 0 && A[st[k]] > A[i])             k--; //we modify the tree as explained above        if (k != -1)             T[i] = st[k];        if (k < top)             T[st[k + 1]] = i; //we insert A[i] in the stack and remove //any bigger elements         st[++k] = i;         top = k;     } //the first element in the stack is the root of //the tree, so it has no father     T[st[0]] = -1; }  
An<O(N), O(1)> algorithm for the restricted RMQ
Now we know that the general RMQ problem can be reduced to the restricted version using LCA. Here, consecutive elements in the array differ by exactly 1. We can use this and give a fast  <O(N), O(1)> algorithm. From now we will solve the RMQ problem for an array  A[0, N - 1] where   |A[i] - A[i + 1]| = 1,  i = [1, N - 1]. We transform  A in a binary array with  N-1 elements, where  A[i] = A[i] - A[i + 1]. It's obvious that elements in  A can be just  +1 or  -1. Notice that the old value of  A[i] is now the sum of  A[1],  A[2] ..  A[i] plus the old A[0]. However, we won't need the old values from now on. 

To solve this restricted version of the problem we need to partition  A into blocks of size  l = [(log N) / 2]. Let  A'[i] be the minimum value for the  i-th block in  A and  B[i] be the position of this minimum value in  A. Both  A and  B are  N/l long. Now, we preprocess  A' using the ST algorithm described in Section1. This will take  O(N/l * log(N/l)) = O(N) time and space. After this preprocessing we can make queries that span over several blocks in  O(1). It remains now to show how the in-block queries can be made. Note that the length of a block is  l = [(log N) / 2], which is quite small. Also, note that  A is a binary array. The total number of binary arrays of size  l is  2l=sqrt(N). So, for each binary block of size  l we need to lock up in a table  P the value for RMQ between every pair of indices. This can be trivially computed in  O(sqrt(N)*l2)=O(N) time and space. To index table  P, preprocess the type of each block in  A and store it in array  T[1, N/l]. The block type is a binary number obtained by replacing -1 with 0 and +1 with 1. 

Now, to answer  RMQA(i, j) we have two cases:
  • i and j are in the same block, so we use the value computed in P and T
  • i and j are in different blocks,  so we compute three values: the minimum from i to the end of i's block using P and T, the minimum of all blocks between i's and j's block using precomputed queries  on A' and the minimum from the begining of j's block to j, again using T and P; finally return the position where the overall minimum is using the three values you just computed.
Conclusion
RMQ and LCA are strongly related problems that can be reduced one to another. Many algorithms can be used to solve them, and they can be adapted to other kind of problems as well. 

Here are some training problems for segment trees, LCA and RMQ: 

SRM 310 ->  Floating Median
http://acm.pku.edu.cn/JudgeOnline/problem?id=1986
http://acm.pku.edu.cn/JudgeOnline/problem?id=2374
http://acmicpc-live-archive.uva.es/nuevoportal/data/problem.php?p=2045
http://acm.pku.edu.cn/JudgeOnline/problem?id=2763
http://www.spoj.pl/problems/QTREE2/
http://acm.uva.es/p/v109/10938.html
http://acm.sgu.ru/problem.php?contest=0&problem=155


References
- " Theoretical and Practical Improvements on the RMQ-Problem, with Applications to LCA and LCE" [PDF] by Johannes Fischer and Volker Heunn
- " The LCA Problem Revisited" [PPT] by Michael A.Bender and Martin Farach-Colton - a very good presentation, ideal for quick learning of some LCA and RMQ aproaches
- " Faster algorithms for finding lowest common ancestors in directed acyclic graphs" [PDF] by Artur Czumaj, Miroslav Kowaluk and Andrzej Lingas 
Xilinx-复旦微-FPGA-眼图BlockDesign系统制作-针对PCIE系统 XIlinx-复旦微电子-FPGA-眼图BlockDesign系统制作-针对PCIE系统,手把手教你如何建立眼图测试 阅读详情

相关推荐

实战指南!基于STM32的智能环境监测系统(代码+硬件设计+云端控制)

本文详细介绍了基于STM32的智能环境监测系统的设计与实现,包括硬件选型、电路设计、软件架构和云端控制。系统通过DHT11温湿度传感器和MQ-2烟雾传感器实时监测环境数据,STM32F103C8T6主控芯片处理数据并通过ESP8266上传至中国移动物联网平台,支持手机APP远程监控。项目成本低、稳定性高,适合智能家居和环境监测应用。

weixin_29194817的博客 433

Range Minimum Query(RMQ) and Lowest Common Ancestor(LCA)

【原文见  http://www.topcoder.com/tc?module=Static&d1=tutorials&d2=lowestCommonAncestor】

志当存高远 1003

25年PINN创新点大盘点!

在科研论文的激烈角逐中,想轻松产出高含金量成果?物理信息神经网络(PINN)堪称“宝藏研究方向”,是冲击高分区论文的绝佳赛道!对于渴望发表优质论文的科研伙伴,这三大研究路径值得重点关注。首先是自适应PINN,在PINN训练过程中,物理方程与实测数据间的矛盾常常导致权重调节困难,而恰好直击这一痛点,是极具价值的研究方向。其次,同样前景广阔,传统多物理场同时训练效果欠佳,如今分阶段训练方法脱颖而出,成效显著且竞争较小。最后,探索及多任务学习等技术的融合,能实现优势叠加,碰撞出创新火花。

Malaai的博客 1973

Range Minimum Query and Lowest Common Ancestor[翻译]

Range Minimum Query and Lowest Common Ancestor 【原文见http://www.topcoder.com/tc?module=Static&d1=tutorials&d2=lowestCommonAncestor】...

chouchijiao8952的博客 178

从谱峰搜索到多项式求根:Root-MUSIC算法原理与MATLAB实践

本文深入解析Root-MUSIC算法在阵列信号处理中的原理与应用,通过多项式求根替代传统MUSIC算法的谱峰搜索,显著提升计算效率和精度。文章详细介绍了算法核心思想、MATLAB实现步骤及工程优化技巧,帮助读者掌握这一高效的DOA估计方法。

weixin_30832143的博客 81

离线AI实战指南:本地部署大模型处理PDF/Word/Excel

离线AI是指在无网络、不上传数据前提下,于个人设备运行大语言模型并完成文档理解、多轮对话与代码辅助等任务的技术方案。其核心依赖本地模型推理、文档解析向量化和轻量级对话调度三大能力。随着Phi-3、Qwen2、Llama3等轻量化开源模型普及,以及Ollama、LM Studio等易用工具成熟,普通用户已可在主流笔记本上实现PDF摘要、合同比对、代码注释等真实办公场景。本文聚焦离线AI的硬件适配、模型选型、文件处理链路与知识库构建,尤其强调中文OCR支持、结构化文档提取与CPU/GPU混合推理优化,助力非开发

weixin_31968639的博客 503

RMQ和LCA

RMQ和LCA 【内容简介】   讨论解决RMQ、LCA问题的算法、以及RMQ、LCA两类问题的相互转换。它们在字符串处理和生物学计算中有着广泛应用,在信息学奥赛中更是被广泛应用和扩展,所以熟练掌握RMQ和LCA问题就显得十分重要。 ※在内容开始,我们假设一个算法预处理时间为 f(n),查询时间为g(n)。这个算法复杂度的标记为(或f(n)-g(n))。 【关键词】RMQ、LCA、ST

1238

Vue3 + MQTT.js 实现 SCADA 实时数据通信:从不稳定到稳定的完整实践

本文介绍了SCADA组态引擎开发中MQTT协议的应用及优化实践。项目采用MQTT协议实现工业设备数据采集与可视化,但面临连接不稳定、数据格式多样化和数据绑定复杂三大问题。针对MQTT连接问题,分析发现超时设置过短(原8秒)、缺少客户端超时配置和心跳机制是主要原因。优化方案包括:协议转换(mqtt://→ws://)、双重超时保护(15秒手动+30秒客户端)、60秒心跳间隔等,显著提升了连接稳定性。通过完整代码实现展示了连接配置、认证处理和错误处理机制,为物联网数据传输提供了可靠解决方案。

weixin_36794508的博客 1404

Range Minimum Query and Lowest Common Ancestor

作者:danielp 出处:http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=lowestCommonAncestor  Introduction  Notations  Range Minimum Query (RMQ)      Trivial algorithms for RMQ      A

liushaobo的专栏 1284

第58篇:AI技术实战:基于深度学习的智能音频内容审核系统

深度学习技术为智能音频内容审核系统提供了强大的支持,通过CNN、RNN和Transformer等模型,能够实现高效的音频内容检测和过滤。使用TensorFlow和Keras可以快速构建和训练音频审核模型,而预训练模型则可以进一步提升性能。数据预处理、特征提取和性能优化是提升智能音频审核系统性能的关键。希望本文的代码示例和注意事项能帮助你更好地理解和应用这些技术。接下来,我们将继续探索更多AI技术实战案例。

加入“Super Entity”,与全能开发团队共探AI智能体与数字人项目,开启前沿技术之旅。 711

YOLOv11 知识蒸馏完整实战:Teacher–Student 训练策略与性能飞跃

在self.alpha = alpha # 蒸馏损失权重self.temperature = temperature # 温度系数,控制分布平滑度# 输出分布蒸馏(KL散度损失)# 中间特征蒸馏(MSE损失,对齐中间层特征)# 总蒸馏损失知识蒸馏是YOLOv11在“小模型高性能部署”场景的“破局之法”——它让小模型能“站在大模型的肩膀上”,兼具速度与精度。从损失函数定义到多阶段训练,再到实战落地,本教程已为你铺就了一条清晰的路径。

m0_64661770的博客 141

学会用rmq解决lca问题

思路:

Holylight_Knight 515

自动驾驶领域自动化数据标注应用

自动驾驶领域自动化数据标注应用 1. 背景介绍 1.1 自动驾驶技术的发展 自动驾驶技术近年来取得了长足的进步,吸引了众多科技公司和传统车企的投入。自动驾驶系统需要感知周围环境、做出决策并控制车辆,是一个极具挑战的任务。其中,环境感知是自

AI天才研究院 2215

约束rmq_约束RMQ

不知道为什么网上找不到太多相关的资料,所以写一个小总结,并附有能用的代码。约束RMQ,就是RMQ区间必须满足两项之差最大为1,采用ST表的话,这时候有O(n)建表,O(1)查询的优秀复杂度求LCA,通过DFS把原树转化为深度序列,就等价于求区间最小值 (取到的位置)由于DFS的性质,该序列两个数之间显然相差1,所以可以使用约束RMQ解决先总体概括一下做法:把原序列分块,块内预处理,块间做ST表分块...

weixin_39631667的博客 103

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

区间节点的lca

题目hdu5266 分析:多节点的LCA就是dfs序中最大最小两个节点的LCA。所以只要每次维持给出节点的dfs序的最大最小,然后就是两点的LCA 代码: rmq的st+lca的倍增 #include<stdio.h> #include<iostream> #include<algorithm> #include<strin...

acs59147的博客 380

贝叶斯统计 [韦来生编]

贝叶斯(Bayes)统计是近几十年来迅速发展起来的数理统计的一个重要分支。贝叶斯方法与经典统计方法的主要不同之处是进行统计推断时除了利用样本信息外,还要利用参数的先验信息,因此可以提高统计推断或统计决策的效果。它在经济、金融、生物、医学、自然科学和社会科学等许多领域具有广泛的应用。贝叶斯方法的研究已渗透到了统计学的几乎所有领域。作者在给中国科学技术大学概率论与数理统计专业本科生开设的“数理统计”课程中有一章专门讲授“贝叶斯方法和统计决策理论”,近十年来也给中国科学技术大学概率统计专业研究生开设过几次“贝叶斯分析”课。本书是在对过去讲稿的内容作了适当的增减和调整的基础上完成的。  本书共分六章。第1章是绪论,介绍了贝叶斯统计的若干基本概念,同时对必要的数理统计的基础知识有重点地作了回顾。第二章介绍了确定先验分布的若干可供选择的方法。第三章介绍了几类常见统计模型参数的后验分布的主要结果和计算方法。第四章和第五章分别介绍了“贝叶斯统计推断”和“贝叶斯统计决策”的内容。第六章介绍了贝叶斯统计计算的若干方法,包括蒙特卡洛方法和马尔可夫链蒙特卡洛(MCMC)方法以及相关统计软件的简介。本书的每一章附右大量的例题和习题,书末附有常用的几个表格和部分习题解答供读者查用。  大约可在54学时内讲授本书的第1章至第六章的主要内容,教师可根据学时需要选讲本书第1章至第六章的部分内容。书中标“*”号的章节可略去不讲,留给读者作为阅读材料。第六章例题中的R代码和部分例题的数据文件等可从作者个人主页下载。  作者在编写本书的过程中参考了J.O.Berger教授的《统计决策论及贝叶斯分析》和茆诗松教授编写的《贝叶斯统计》等书中的一些内容,以及《贝叶斯分析》一书中由张伟平博士编写的有关贝叶斯统计计算的一些内容。在此表示衷心感谢。  本书编写准备过程中,中国科学技术大学统计与金融系的几个研究生帮助完成了本书部分中文的录入和排版,作者对他们的辛勤工作表示真诚的感谢。高等教育出版社为本书的出版给予了大力支持。在此一并致谢。

ST表&LCA&RMQ

SparseTable RMQ问题 RMQ (Range Minimum/Maximum Query)问题是指:对于长度为n的数列A,回答若干询问RMQ(A,i,j)(i,j<=n),返回数列A中下标在i,j里的最小(大)值,也就是说,RMQ问题是指求区间最值的问题。 算法 朴素(即搜索),O(n)-O(qn)online。 线段树,O(n)-O(qlogn)online。(这个稍后补...

Dawn-K の Blog 847

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

上一篇: linux下fork一道面试题目
下一篇: 汉字编码问题(转)
TheAlgorithmArt
博客等级 码龄16年 6粉丝 12原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值