![Latex 算法标准](https://linux22.com/image/353045/Latex%20%E7%AE%97%E6%B3%95%E6%A0%87%E5%87%86%20.png)
我已经为自己编写的一些伪代码编写了一些乳胶代码,其用途如下:
\usepackage{amsmath}
\usepackage{algorithm}
\usepackage[noend]{algpseudocode}
我想知道乳胶中的算法是否有一个标准,或者只是一般的算法?
我应该使用平方根还是 sqrt (state),我是否应该通过state[i]
使用分数还是仅使用除法符号来访问数组项?
以下是代码:
\makeatletter
\def\BState{\State\hskip-\ALG@thistlm}
\makeatother
%this changes the style of the comments
\begin{algorithm}
\caption{Manhattan Distance}\label{euclid}
\begin{algorithmic}[1]
\Procedure{ManDist}{$state$} \Comment{The current puzzle configuration }
\State$total\gets 0$
\State$puzzleLength\gets sizeOf(state)$
\State$dimensions\gets \sqrt{puzzleLength}$
\For{$i\gets 1, puzzleLength$} \Comment{Loops through each tile of the puzzle}
\State $tileValue\gets state[i]$
\State $expectedRow\gets \dfrac{(tileValue -1)}{dimensions}$
\State $expectedCol\gets (tileValue -1)\bmod dimensions$
\State $rowNum \gets \dfrac{i}{dimensions}$
\State $rowNum\gets i \bmod dimensions$
\State $total\gets total \texttt{+} \mid{expectedRow-rowNum}\mid\texttt{+}\mid{expectedCol-colNum}\mid$
\EndFor
\State \textbf{return} $total$\Comment{The heuristic is the total}
\EndProcedure
\end{algorithmic}
\end{algorithm}