构建后,乳胶中不会维护顺序

sat*_*sat 1 latex

\subsubsection{Greedy}
Run Code Online (Sandbox Code Playgroud)

代码片段:

A greedy coloring is a coloring of the vertices of a graph formed by a greedy algorithm that considers the vertices of the graph in sequence and assigns each vertex its first available color. Greedy colorings do not in general use the minimum number of colors possible. However, they have been used in mathematics as a technique for proving other results about colorings and in computer science as a heuristic to find colorings with few colors. In this heuristic algorithm, once a vertex is colored, its color never changes.

\textbf{Input:} A simple undirected graph G with vertices $V(G)$ = {$v_{1}$, $v_{2}$, . . . , $v_{n}$}. (The list of colors to be drawn from will be {1, 2, . . ., n}; GCA does not necessarily use all of these colors.\\
\textbf{Output:} A vertex-coloring of G.
\paragraph{Basic Algorithm:\\}

\begin{algorithm}
\caption{Greedy Coloring Algorithm}
\label{GCA}
\begin{algorithmic}[1]
\FOR{$i = 1$ to $n$} 
\STATE $L_{i}$ =$\lbrace$1,...,i$\rbrace$($L_{i}$ is the list of colors that may be assigned to $v_{i}$)
\ENDFOR
\FOR{$i = 1$ to $n$} 
\STATE $C_{i}$ $\leftarrow$ the first color in $L_{i}$( $C_{i}$ is the color assigned to $v_{i}$)
\ENDFOR \\
\WHILE{$i$ $<$ $j$ and ($v_{i}$,$v_{j}$)$\neq$ E(G)} 

\STATE $L_{j}$ $:=$ $L_{j}$ $\backslash$ $C_{i}$
\ENDWHILE
\STATE Return each vertex, the color it was assigned, and the total number of colors used.
\end{algorithmic}
\end{algorithm}
\paragraph{Findings}
Time Complexity: O($V^{2}$ + E) in worst case.
Run Code Online (Sandbox Code Playgroud)

pdf格式: image3

乳胶中的问题 在此输入图像描述

我面临的问题是纸张中没有维护顺序。我想按照我用乳胶书写的顺序查看纸张。但这并没有发生。 图片1 图片2 图片3

Wer*_*ner 6

这里的主要问题是您在环境中编写了算法algorithm,该环境像figure或 一样浮动table。如果您想要与您的输入相匹配的顺序呈现(输出),那么您可能需要尝试如下操作:

在此输入图像描述

\documentclass{article}

\usepackage{algorithm,algcompatible,amsmath}
\usepackage{lipsum}% Just for this example

\newcommand{\bigO}[1]{\mathcal{O}(#1)}
\algnewcommand\INPUT{\item[\textbf{Input:}]}%
\algnewcommand\OUTPUT{\item[\textbf{Output:}]}%
\newcommand{\AlgBlankLine}{\par\nobreak\vspace*{.5\baselineskip}}

\begin{document}

\lipsum[1]

\paragraph{Basic Algorithm}\leavevmode

\begin{algorithm}[H]
\caption{Greedy Coloring Algorithm (GCA)}\label{GCA}
  \begin{algorithmic}[1]
    \INPUT A simple undirected graph~$G$ with vertices $V(G) = \{v_1, v_2, \dots, v_n\}$. (The list of colors to be drawn from will be $\{1, 2, \dots, n\}$; 
      GCA does not necessarily use all of these colors.)
    \OUTPUT A vertex-coloring of~$G$.
    \AlgBlankLine
    \FOR{$i = 1$ to $n$}
      \STATE $L_i = \{1,\dots,i\}$ ($L_i$ is the list of colors that may be assigned to~$v_i$)
    \ENDFOR
    \FOR{$i = 1$ to $n$}
      \STATE $C_i \leftarrow \text{the first color in $L_i$}$ ($C_i$ is the color assigned to~$v_i$)
    \ENDFOR
    \WHILE{$i < j$ and $(v_i,v_j) \neq E(G)$}
      \STATE $L_j := L_j \setminus C_i$
    \ENDWHILE
    \STATE Return each vertex, the color it was assigned, and the total number of colors used.
  \end{algorithmic}
\end{algorithm}

\paragraph{Findings}%
Time Complexity: $\bigO{V^2 + E}$ in worst case.

\end{document}
Run Code Online (Sandbox Code Playgroud)

请注意以下事项:

  1. 我使用了algorithmicx包的格式和布局而不是纯algorithmic. 后者从algorithms包中加载提供浮点说明符的float[H]。这会将浮动的行为更改为 STAY HERE 并且不再浮动。

  2. 将您的输入输出作为算法的一部分。这更有意义。

  3. \leavevmode(或\mbox{})在后面很重要,\paragraph{Basic Algorithm}因为它实际上是该段落的开始。

  4. 其他一些格式更新。

我的偏好是在文本中引用算法,并让它浮动在文档中可能需要的位置。使用上述[H]浮点说明符会将algorithm块放置到位并对应于您的 LaTeX 输入,但如果块出现在页面边界周围,也会导致问题。让它漂浮可以避免这种情况。