在线LATex
作为中文毕业论文,还是要输入中文的,所以对overleaf做一些设置比较好
-
选中菜单
image.png -
编译器选择:
image.png - 在代码中加入utf-8的包
\usepackage[UTF8]{ctex}
在网上看到的比较好的模版:模版
\documentclass[11pt]{ctexart}
\usepackage[top=2cm, bottom=2cm, left=2cm, right=2cm]{geometry}
\usepackage{algorithm}
\usepackage{algorithmicx}
\usepackage{algpseudocode}
\usepackage{amsmath}
\usepackage[UTF8]{ctex}
\floatname{algorithm}{算法}
\renewcommand{\algorithmicrequire}{\textbf{输入:}}
\renewcommand{\algorithmicensure}{\textbf{输出:}}
\begin{document}
\begin{algorithm}
\caption{算法}
\begin{algorithmic}[1] %每行显示行号
\Require $Array$数组,$n$数组大小
\Ensure 逆序数
\Function {MergerSort}{$Array, left, right$}
\State $result \gets 0$
\If {$left < right$}
\State $middle \gets (left + right) / 2$
\State $result \gets result +$ \Call{MergerSort}{$Array, left, middle$}
\State $result \gets result +$ \Call{MergerSort}{$Array, middle, right$}
\State $result \gets result +$ \Call{Merger}{$Array,left,middle,right$}
\EndIf
\State \Return{$result$}
\EndFunction
\State
\Function{Merger}{$Array, left, middle, right$}
\State $i\gets left$
\State $j\gets middle$
\State $k\gets 0$
\State $result \gets 0$
\While{$i<middle$ \textbf{and} $j<right$}
\If{$Array[i]<Array[j]$}
\State $B[k++]\gets Array[i++]$
\Else
\State $B[k++] \gets Array[j++]$
\State $result \gets result + (middle - i)$
\EndIf
\EndWhile
\While{$i<middle$}
\State $B[k++] \gets Array[i++]$
\EndWhile
\While{$j<right$}
\State $B[k++] \gets Array[j++]$
\EndWhile
\For{$i = 0 \to k-1$}
\State $Array[left + i] \gets B[i]$
\EndFor
\State \Return{$result$}
\EndFunction
\end{algorithmic}
\end{algorithm}
\end{document}
网友评论