From 9e625b89bac7e8daaf583e215f3a0df3dc250bb2 Mon Sep 17 00:00:00 2001 From: Paul Jungeblut Date: Mon, 27 Jun 2016 11:17:34 +0200 Subject: Math section rebuild, merged convinience and sonstiges section. --- sonstiges/bitOps.cpp | 15 +++++++-------- sonstiges/josephus2.cpp | 2 +- sonstiges/josephusK.cpp | 2 +- sonstiges/sonstiges.tex | 28 ++++++++++++++++++++++++++++ sonstiges/split.cpp | 9 +++++++++ 5 files changed, 46 insertions(+), 10 deletions(-) create mode 100644 sonstiges/split.cpp (limited to 'sonstiges') diff --git a/sonstiges/bitOps.cpp b/sonstiges/bitOps.cpp index b882965..b75304f 100644 --- a/sonstiges/bitOps.cpp +++ b/sonstiges/bitOps.cpp @@ -1,15 +1,14 @@ -//lsb: 0-th bit, msb: n-th bit -//get j-th bit +// Bit an Position j auslesen. (a & (1 << j)) != 0 -//set j-th bit +// Bit an Position j setzen. a |= (1 << j) -//clear j-th bit +// Bit an Position j löschen. a &= ~(1 << j) -//toggle j-th bit +// Bit an Position j umkehren. a ^= (1 << j) -//get value of least significant bit set +// Wert des niedrigsten gesetzten Bits. (a & -a) -//turn on all bits +// Setzt alle Bits auf 1. a = -1 -//turn on first n bits (be aware of overflows) +// Setzt die ersten n Bits auf 1. Achtung: Overflows. a = (1 << n) - 1 diff --git a/sonstiges/josephus2.cpp b/sonstiges/josephus2.cpp index 7676e3c..c0bcc2f 100644 --- a/sonstiges/josephus2.cpp +++ b/sonstiges/josephus2.cpp @@ -1,4 +1,4 @@ -int rotateLeft(int n) { //returns the number of the last survivor (1 based) +int rotateLeft(int n) { // Gibt Index des letzten Überlebenden zurück, 1-basiert. for (int i = 31; i >= 0; i--) if (n & (1 << i)) { n &= ~(1 << i); diff --git a/sonstiges/josephusK.cpp b/sonstiges/josephusK.cpp index e3fcac2..8758fee 100644 --- a/sonstiges/josephusK.cpp +++ b/sonstiges/josephusK.cpp @@ -1,4 +1,4 @@ -int josephus(int n, int k) { //returns the number of the last survivor (0 based) +int josephus(int n, int k) { // Gibt Index des letzten Überlebenden zurück, 0-basiert. if (n == 1) return 0; return (josephus(n - 1, k) + k) % n; } \ No newline at end of file diff --git a/sonstiges/sonstiges.tex b/sonstiges/sonstiges.tex index b2d9009..8148dbf 100644 --- a/sonstiges/sonstiges.tex +++ b/sonstiges/sonstiges.tex @@ -8,6 +8,9 @@ \item Genau dann lösbar, wenn keine Variable mit ihrer Negation in einer SCC liegt. \end{enumerate} +\subsection{Zeileneingabe} +\lstinputlisting{sonstiges/split.cpp} + \subsection{Bit Operations} \lstinputlisting{sonstiges/bitOps.cpp} @@ -59,3 +62,28 @@ $n$ Personen im Kreis, jeder $k$-te wird erschossen. Lösung: Sortiere Knoten links aufsteigend nach Gewicht, danach nutze normlen Algorithmus (\textsc{Kuhn}, Seite \pageref{kuhn}) \item \textbf{Tobi, cool down!} \end{itemize} + +\subsection{Sonstiges} +\begin{lstlisting} +// Alles-Header. +#include + +// Setzt das deutsche Tastaturlayout. +setxkbmap de + +// Schnelle Ein-/Ausgabe mit cin/cout. +ios::sync_with_stdio(false); + +// Set mit eigener Sortierfunktion. Typ muss nicht explizit angegeben werden. +set set1(comp); + +// PI +#define PI (2*acos(0)) + +// STL-Debugging, Compiler flags. +-D_GLIBCXX_DEBUG +#define _GLIBCXX_DEBUG + +// 128-Bit Integer. Muss zum Einlesen/Ausgeben in einen int oder long long gecastet werden. +__int128 +\end{lstlisting} diff --git a/sonstiges/split.cpp b/sonstiges/split.cpp new file mode 100644 index 0000000..ea7d5ff --- /dev/null +++ b/sonstiges/split.cpp @@ -0,0 +1,9 @@ +vector split(string &s, string delim) { // Zerlegt s anhand aller Zeichen in delim. + vector result; char *token; + token = strtok((char*)s.c_str(), (char*)delim.c_str()); + while (token != NULL) { + result.push_back(string(token)); + token = strtok(NULL, (char*)delim.c_str()); + } + return result; +} \ No newline at end of file -- cgit v1.2.3