Sorry, your browser cannot access this site
This page requires browser support (enable) JavaScript
Learn more >

比特操作

\mathbin{\&} % and
\mathbin{|} % or
\ll % shift left
\gg % shift right
\ensuremath{\mathord{\sim}} % not

伪代码举例

文档参考:https://www.overleaf.com/learn/latex/Algorithms
在premmable中引入包\usepackage{algorithm}\usepackage{algpseudocode}
在document中

Algorithm A is shown in list \ref{alg:msbfs}. 

\begin{algorithm}
\caption{MS-BFS}\label{alg:msbfs}

\begin{algorithmic}[1] % 1: 有行编号,从1开始
\State \textbf{Input:} $G, \textbf{B}, S$ \Comment{\textbf{B}: a set of BFSes}
\For{each $bi \in \textbf{B}$}
    \State $seen[ si ] \gets 1 \ll bi$
    \State $visit[ si ] \gets 1 \ll bi$
\EndFor
\State reset $visitNext$
\While{$visit \neq \emptyset$}
    \For{$i = 1, . . . , N$}
        \If{$visit[vi] = \textbf{B}_{\emptyset}$} \Comment{$\textbf{B}_{\emptyset}$: empty BFS set}
            \State skip
        \EndIf
        \For{each $n \in neighbors[vi]$}
            \State $D \gets visit[vi] \mathbin{\&} \ensuremath{\mathord{\sim}}seen[n]$
            \If{$D \neq \textbf{B}_{\emptyset}$}
                \State $visitNext[n] \gets visitNext[n] \mathbin{|} D$
                \State $seen[n] \gets seen[n] \mathbin{|} D$
                \State do BFS computation on $n$
            \EndIf
        \EndFor
    \EndFor
    \State $visit \gets visitNext$
    \State reset $visitNext$
\EndWhile
\end{algorithmic}

\end{algorithm}

效果:

评论