1、添加宏包algorithm与algorithmic:\usepackage{algorithm, algorithmic}
2、开始算法环境:\begin{algorithm}结束的时候要\end{algorithm}
3、把下面algorithmic环境中的require和ensure给替换为Input和Output\renewcommand{\algorithmicrequire}{\textbf{Input:}} \renewcommand{\algorithmicensure}{\textbf{Output:}}添加caption和label等\caption{}\label{}
4、开始algorithmic环境,\begin{algorithmic}[1] \REQUIRE 输入元素 \ENSURE 输出元素如果没有上面那个替换,会在pdf中显示Require和Ensure。最后结束要\end{algorithmic}
5、然后每一个state表示一行,会有序号\STATE 内容
6、也可以加for循环\FORALL \IN\ENDFOR