Small fixes

This commit is contained in:
Antti H S Laaksonen 2017-12-10 12:06:32 +02:00
parent 3d8961e703
commit 761a9128e7
7 changed files with 20 additions and 20 deletions

View File

@ -35,9 +35,9 @@ straightforward and concise.
Programs should be written quickly, Programs should be written quickly,
because there is not much time available. because there is not much time available.
Unlike in traditional software engineering, Unlike in traditional software engineering,
the programs are short (usually at most some the programs are short (usually at most a few
hundreds of lines) and it is not needed to hundred lines of code), and they do not need to
maintain them after the contest. be maintained after the contest.
\section{Programming languages} \section{Programming languages}
@ -56,7 +56,7 @@ Many people think that C++ is the best choice
for a competitive programmer, for a competitive programmer,
and C++ is nearly always available in and C++ is nearly always available in
contest systems. contest systems.
The benefits in using C++ are that The benefits of using C++ are that
it is a very efficient language and it is a very efficient language and
its standard library contains a its standard library contains a
large collection large collection
@ -154,7 +154,7 @@ This kind of code always works,
assuming that there is at least one space assuming that there is at least one space
or newline between each element in the input. or newline between each element in the input.
For example, the above code can read For example, the above code can read
both the following inputs: both of the following inputs:
\begin{lstlisting} \begin{lstlisting}
123 456 monkey 123 456 monkey
\end{lstlisting} \end{lstlisting}

View File

@ -14,7 +14,7 @@ The \key{time complexity} of an algorithm
estimates how much time the algorithm will use estimates how much time the algorithm will use
for some input. for some input.
The idea is to represent the efficiency The idea is to represent the efficiency
as an function whose parameter is the size of the input. as a function whose parameter is the size of the input.
By calculating the time complexity, By calculating the time complexity,
we can find out whether the algorithm is fast enough we can find out whether the algorithm is fast enough
without implementing it. without implementing it.

View File

@ -248,7 +248,7 @@ a solution can be constructed.
As an example, consider the problem of As an example, consider the problem of
calculating the number calculating the number
of ways $n$ queens can be placed to of ways $n$ queens can be placed on
an $n \times n$ chessboard so that an $n \times n$ chessboard so that
no two queens attack each other. no two queens attack each other.
For example, when $n=4$, For example, when $n=4$,
@ -276,10 +276,10 @@ there are two possible solutions:
The problem can be solved using backtracking The problem can be solved using backtracking
by placing queens to the board row by row. by placing queens to the board row by row.
More precisely, exactly one queen will More precisely, exactly one queen will
be placed to each row so that no queen attacks be placed on each row so that no queen attacks
any of the queens placed before. any of the queens placed before.
A solution has been found when all A solution has been found when all
$n$ queens have been placed to the board. $n$ queens have been placed on the board.
For example, when $n=4$, For example, when $n=4$,
some partial solutions generated by some partial solutions generated by
@ -358,7 +358,7 @@ void search(int y) {
\end{lstlisting} \end{lstlisting}
\end{samepage} \end{samepage}
The search begins by calling \texttt{search(0)}. The search begins by calling \texttt{search(0)}.
The size of the board is $n$, The size of the board is $n \times n$,
and the code calculates the number of solutions and the code calculates the number of solutions
to \texttt{count}. to \texttt{count}.
@ -366,7 +366,7 @@ The code assumes that the rows and columns
of the board are numbered from 0 to $n-1$. of the board are numbered from 0 to $n-1$.
When the function \texttt{search} is When the function \texttt{search} is
called with parameter $y$, called with parameter $y$,
it places a queen to row $y$ it places a queen on row $y$
and then calls itself with parameter $y+1$. and then calls itself with parameter $y+1$.
Then, if $y=n$, a solution has been found Then, if $y=n$, a solution has been found
and the variable \texttt{count} is increased by one. and the variable \texttt{count} is increased by one.
@ -446,11 +446,11 @@ the $4 \times 4$ board are numbered as follows:
\end{center} \end{center}
Let $q(n)$ denote the number of ways Let $q(n)$ denote the number of ways
to place $n$ queens to an $n \times n$ chessboard. to place $n$ queens on an $n \times n$ chessboard.
The above backtracking The above backtracking
algorithm tells us that, for example, $q(8)=92$. algorithm tells us that, for example, $q(8)=92$.
When $n$ increases, the search quickly becomes slow, When $n$ increases, the search quickly becomes slow,
because the number of the solutions increases because the number of solutions increases
exponentially. exponentially.
For example, calculating $q(16)=14772512$ For example, calculating $q(16)=14772512$
using the above algorithm already takes about a minute using the above algorithm already takes about a minute

View File

@ -333,8 +333,8 @@ the sets $x=\{1,3,4,8\}$ and $y=\{3,6,8,9\}$,
and then constructs the set $z = x \cup y = \{1,3,4,6,8,9\}$: and then constructs the set $z = x \cup y = \{1,3,4,6,8,9\}$:
\begin{lstlisting} \begin{lstlisting}
int x = (1<<1)+(1<<3)+(1<<4)+(1<<8); int x = (1<<1)|(1<<3)|(1<<4)|(1<<8);
int y = (1<<3)+(1<<6)+(1<<8)+(1<<9); int y = (1<<3)|(1<<6)|(1<<8)|(1<<9);
int z = x|y; int z = x|y;
cout << __builtin_popcount(z) << "\n"; // 6 cout << __builtin_popcount(z) << "\n"; // 6
\end{lstlisting} \end{lstlisting}
@ -804,7 +804,7 @@ that only elements $0 \ldots k$
may be removed from $S$. may be removed from $S$.
For example, For example,
\[\texttt{partial}(\{0,2\},1)=\texttt{value}[\{2\}]+\texttt{value}[\{0,2\}],\] \[\texttt{partial}(\{0,2\},1)=\texttt{value}[\{2\}]+\texttt{value}[\{0,2\}],\]
because we only may remove elements $0 \ldots 1$. because we may only remove elements $0 \ldots 1$.
We can calculate values of \texttt{sum} using We can calculate values of \texttt{sum} using
values of \texttt{partial}, because values of \texttt{partial}, because
\[\texttt{sum}(S) = \texttt{partial}(S,n-1).\] \[\texttt{sum}(S) = \texttt{partial}(S,n-1).\]

View File

@ -350,7 +350,7 @@ while (!q.empty()) {
Using the graph traversal algorithms, Using the graph traversal algorithms,
we can check many properties of graphs. we can check many properties of graphs.
Usually, both depth-first search and Usually, both depth-first search and
bredth-first search may be used, breadth-first search may be used,
but in practice, depth-first search but in practice, depth-first search
is a better choice, because it is is a better choice, because it is
easier to implement. easier to implement.

View File

@ -3,7 +3,7 @@
\index{spanning tree} \index{spanning tree}
A \key{spanning tree} of a graph consists of A \key{spanning tree} of a graph consists of
the nodes of the graph and some of the all nodes of the graph and some of the
edges of the graph so that there is a path edges of the graph so that there is a path
between any two nodes. between any two nodes.
Like trees in general, spanning trees are Like trees in general, spanning trees are

View File

@ -5,8 +5,8 @@
The purpose of this book is to give you The purpose of this book is to give you
a thorough introduction to competitive programming. a thorough introduction to competitive programming.
It is assumed that you already It is assumed that you already
know the basics of programming, but previous know the basics of programming, but no previous
background on competitive programming is not needed. background in competitive programming is needed.
The book is especially intended for The book is especially intended for
students who want to learn algorithms and students who want to learn algorithms and