% Macros para problemas da Maratona de Programacao ACM 2001
% \newcommand{\lastedit}{2001-11-15 15:14:14 by stolfi}
% do curso MC202 - Estruturas de Dados
% 2o. semestre de 1994 -- Jorge Stolfi

\makeatletter \endlinechar=-1

% Cabecalhos

% Headings:

  \def\ps@myheadings{
    \let\@mkboth\markboth
    \def\@oddfoot{}
    \def\@evenfoot{}
    \def\@evenhead{\rm \thepage\hfil \sl \leftmark}
    \def\@oddhead{\hbox{}\sl \rightmark \hfil \rm\thepage}
    \def\chaptermark##1{
      \markboth{\sl {\ifnum \c@secnumdepth >\m@ne \@chapapp\ \thechapter. \ \fi ##1}}{}
    }
    \def\sectionmark##1{
      \markright{\sl{\ifnum \c@secnumdepth >\z@ \thesection. \ \fi ##1}}
    }
  }

  \pagestyle{myheadings}
  
% Margins:

  \setlength{\oddsidemargin}{\evensidemargin}

% Fontes:

  \newcommand{\matfn}{\sf}  % Matrizes
  \newcommand{\kwfn}{\bf}   % Palavras chaves
  \newcommand{\varfn}{\it}  % Identificadores de algoritmos

  % \DeclareSymbolFontAlphabet{\Bbb}{AMSb}
  
% Fontes para programas

  \renewcommand{\v}[1]{\hbox{\varfn #1}} % Program variable
  \renewcommand{\k}[1]{\hbox{\kwfn #1}} % Valores de enumeracoes
  
% Esimos, esimas

  \newcommand{\esimo}{\raisebox{.6ex}{\b{o}}$\,$}
  \newcommand{\esimos}{\raisebox{.6ex}{\b{os}}$\,$}
  \newcommand{\esima}{\raisebox{.6ex}{\b{a}}$\,$}
  \newcommand{\esimas}{\raisebox{.6ex}{\b{as}}$\,$}
  
% Abreviacoes:

  \let\ds\displaystyle
  \let\ph\phantom
  \def\up{{\uparrow}}

% Dois pontinhos

  \newcommand{\dd}{\mathinner{\ldotp\ldotp}}
  \newcommand{\cdd}{\mathinner{\cdotp\cdotp}}
  \newcommand{\vdd}{\vbox{\baselineskip 4pt\lineskiplimit 0pt\kern 6pt\hbox{.}\hbox{.}}}

% Intervalos reais -- uso: [0\spn 1]

  \newcommand{\spn}{\mathrel{{\_\kern-2pt\_}}}

% Parenteses quebrados

  \newcommand{\la}{\langle}
  \renewcommand{\ra}{\rangle}

% Conjuntos

  \newcommand{\set}[1]{{\left\{#1\right\}}}       % Uso: \set{1,2,3}
  \newcommand{\rset}[1]{{\left\{\,#1\,\right\}}}  % Uso: \rset{x\suchthat P(x)}
  \newcommand{\suchthat}{\mathrel{\;:\;}}
  
  \newcommand{\inte}{\cap}
  \newcommand{\uni}{\cup}

% Determinante, comprimento, modulo, sinal:

  \renewcommand{\det}[1]{{\left|#1\right|}}
  \newcommand{\abs}[1]{{\left|{#1}\right|}}

% Operadores geometricos

  \newcommand{\norm}{\mathop{\rm norm}}
  \newcommand{\dist}{\mathop{\rm dist}}
  \newcommand{\dir}{\mathop{\rm dir}}
  \newcommand{\bbox}{\mathop{\rm bbox}}

  \newcommand{\sign}{\mathop{\rm sgn}}

  \newcommand{\dotprod}{\mathbin{{\large \cdot}}}

  \newcommand{\orient}{\mathop{\Delta}}  % Orientacao de triangulo

  \newcommand{\lado}{\diamond}  % Lado de uma reta que contem um ponto
  
  \newcommand{\join}{\vee}
  \newcommand{\meet}{\wedge}
  
% Matriz transposta e inversa

  \newcommand{\transp}[1]{{#1}^\top}
  \newcommand{\inv}[1]{{#1}^{-1}}

% Simbolos matematicos diversos

  \def\ic{{\bf i}}   % Imaginary unit i
  \def\iq{{\bf i}}   % Quaternion unit I
  \def\jq{{\bf j}}   % Quaternion unit J
  \def\kq{{\bf k}}   % Quaternion unit K

% Letras gregas:

  % Gosto mais do varepsilon do que do epsilon:
  \let\f@@\epsilon
  \let\epsilon\varepsilon
  \let\varepsilon\f@@
  \let\f@@\undef

  \let\eps\epsilon
  \let\lam\lambda
  \let\sig\sigma
  \let\gam\gamma
  \let\alf\alpha
  \let\bet\beta
  \let\del\delta
  \let\tet\theta
  \let\kap\kappa
  
% Espacos matematicos

  \newcommand{\BR}{{\Bbb R}}
  \newcommand{\BP}{{\Bbb P}}
  \newcommand{\BT}{{\Bbb T}}
  \newcommand{\BS}{{\Bbb S}}
  \newcommand{\BN}{{\Bbb N}}

% Letras caligraficas

  \newcommand{\SA}{{\cal A}}
  \newcommand{\SB}{{\cal B}}
  \newcommand{\SC}{{\cal C}}
  \newcommand{\SD}{{\cal D}}
  \newcommand{\SE}{{\cal E}}
  \newcommand{\SF}{{\cal F}}
  \newcommand{\SG}{{\cal G}}
  \newcommand{\SH}{{\cal H}}
  \newcommand{\SI}{{\cal I}}
  \newcommand{\SJ}{{\cal J}}
  \newcommand{\SK}{{\cal K}}
  \newcommand{\SL}{{\cal L}}
  \newcommand{\SM}{{\cal M}}
  \newcommand{\SN}{{\cal N}}
  \newcommand{\SO}{{\cal O}}
  \newcommand{\SP}{{\cal P}}
  \newcommand{\SQ}{{\cal Q}}
  \newcommand{\SR}{{\cal R}}
  \renewcommand{\SS}{{\cal S}}
  \newcommand{\ST}{{\cal T}}
  \newcommand{\SU}{{\cal U}}
  \newcommand{\SV}{{\cal V}}
  \newcommand{\SW}{{\cal W}}
  \newcommand{\SX}{{\cal X}}
  \newcommand{\SY}{{\cal Y}}
  \newcommand{\SZ}{{\cal Z}}

% Nomes de matrizes:

  \newcommand{\MM}{{\matfn M}}
  \newcommand{\MN}{{\matfn N}}
  \newcommand{\MF}{{\matfn F}}
  \newcommand{\MG}{{\matfn G}}
  \newcommand{\MR}{{\matfn R}}
  \newcommand{\MS}{{\matfn S}}
  \newcommand{\MH}{{\matfn H}}
  \newcommand{\MP}{{\matfn P}}
  \newcommand{\MV}{{\matfn V}}
  \newcommand{\MT}{{\matfn T}}

  \newcommand{\Mf}{{\matfn f}}
  \newcommand{\Mp}{{\matfn p}}

% Bibliografia:

  \newcommand{\autor}[1]{{\rm #1:}}
  \newcommand{\titulo}[1]{{\it #1}}
  \newcommand{\editora}[1]{{\rm #1.}}

% Teoremas, propriedades, definicoes:

  \newtheorem{property}{Propriedade}[chapter]
  \newtheorem{definition}{Defini\c{c}\~ao}[chapter]
  \newtheorem{lemma}{Lema}[chapter]
  \newtheorem{theorem}{Teorema}[chapter]

  \def\prova#1{\noindent{\bf Prova\ifx#1\relax:\else
  {} {\rm(#1):}\fi}%
  \list{}{\listparindent 0pt\itemindent\listparindent
  \topsep=0pt\partopsep=0pt
  \rightmargin\leftmargin\parsep 0pt}\item[]}
  \let\endprova=\endlist

  \def\qed{\hbox{}\hfill\fbox{\vrule width 0pt height 4pt depth 0pt}}

% Notas editoriais

  \newcommand{\bug}{\hbox{\vrule height8pt depth 2pt width 10pt\message{***BUG***}}}

  \newcommand{\ednote}[1]{\ednotemark{\rm [#1]}}
  \newcommand{\ednotemark}{
    \ifvmode
      \noindent\hbox to 0pt{\hss\Large $\star$\kern 5pt}
    \else
      \hbox{\Large $\star$}
    \fi
  }

% Exercicios

  \newcounter{exerc}[chapter]
  \newcounter{exsave}
  \renewcommand{\theexerc}{\thechapter.\arabic{exerc}}

  \newenvironment{exerc}
    {
      \refstepcounter{exerc}
      \begin{list}
	{\theexerc}
	{
	  \setlength{\leftmargin}{1em}
	  \setlength{\rightmargin}{\leftmargin}
	  % Push item labels flush with left margin: 
	  \setlength{\labelwidth}{0pt}
	  \setlength{\labelsep}{0pt}
	  \setlength{\itemindent}{\labelwidth}
	  \addtolength{\itemindent}{\labelsep}
          % Start numbering where we left off:
          \setcounter{exsave}{\value{exerc}}
          \usecounter{exerc}
          \setcounter{exerc}{\value{exsave}}
          \addtocounter{exerc}{-1}
	  \def\makelabel##1{\hss\bf Ex. ##1:\ }
	}
      \small\item
    }
    {
      \end{list}
    }

% Algoritmos:

  \newtheorem{algorithm}{Algoritmo}[chapter]

  \newenvironment{algbody}
    {
      \renewcommand{\theenumi}{\arabic{enumi}}
      %
      \renewcommand{\theenumii}{\arabic{enumii}}
      \renewcommand{\p@enumii}{\theenumi.}
      \renewcommand{\labelenumii}{\theenumi.\theenumii.}
      %
      \renewcommand{\theenumiii}{\arabic{enumiii}}
      \renewcommand{\p@enumiii}{\theenumi.\theenumii.}
      \renewcommand{\labelenumiii}{\theenumi.\theenumii.\theenumiii.}
      %
      \renewcommand{\theenumiv}{\arabic{enumiv}}
      \renewcommand{\p@enumiv}{\theenumi.\theenumii.\theenumiii.}
      \renewcommand{\labelenumiv}{\theenumi.\theenumii.\theenumiii.\theenumiv.}
      %
      \def\step{\item}
      \list
        {}
	{ \listparindent=0pt
	  \itemindent=\listparindent
	  \topsep=0pt\partopsep=0pt
          \rightmargin=1em
	  \leftmargin=0pt
	  \itemsep=0pt
	  \parsep=0pt
        }
        \item[] 
        \begin{enumerate}
    }
    {
        \end{enumerate}
      \endlist
      \vspace{1.5ex}
    }

  \newenvironment{block}
    {
      \begin{enumerate}
      \setlength{\itemsep}{2pt}
    }
    {
      \end{enumerate}
    }

% Figuras

  % Usage: \fighere{box}{label}{caption}

  \newcommand{\fighere}[3]{\bigskip
    \vbox{\offinterlineskip
      \captionbox{\hbox to \hsize{\hfil#1\hfil}}{figure}{#2}{#3}
      \vskip 5pt
    }
  }
  
  % Usage: \figfloat{box}{label}{caption}

  \newcommand{\figfloat}[3]{
    \begin{figure}[hbt]
      \hbox to \hsize{\hfil#1\hfil}
      \caption{#2}
      \label{#3}
    \end{figure}
  }

  \newcommand{\hvsmash}[1]{
    \vbox to 0pt{
      \hbox to 0pt{}
      \vss
      \hbox to 0pt{\hss #1\hss}
      \vss
      \hbox to 0pt{}
    }
  }

  \newcommand{\piece}[5]{
    \hbox{
      \framebox{
        \vbox to 15mm{
          \hbox to 15mm{\hss\small\it #4\hss}
          \vss
          \hbox to 15mm{{\small\it #5}\hss\hvsmash{\large\tt #1}\hss{\small\it #3}}
          \vss
          \hbox to 15mm{\hss\small\it #2\hss}
        }
      }
      \kern 1pt
    }
  }
  
  \newcommand{\hstack}[1]{\hbox{$\vcenter{\hbox{#1}}$}}
  \newcommand{\vstack}[1]{\hbox{$\vcenter{#1}$}}

\makeatother \endlinechar=`\^^M
