From 8f2d39fbb269d711b78ba15f46d01bdc8d6a5e1e Mon Sep 17 00:00:00 2001 From: baluteshih Date: Sat, 21 Oct 2023 02:09:12 +0800 Subject: [PATCH] Add random stuff from ckiseki --- codebook/9_Else/BitsetLCS.cpp | 9 +++++++++ codebook/9_Else/NQueens.cpp | 16 ++++++++++++++++ codebook/content.tex | 4 ++++ 3 files changed, 29 insertions(+) create mode 100644 codebook/9_Else/BitsetLCS.cpp create mode 100644 codebook/9_Else/NQueens.cpp diff --git a/codebook/9_Else/BitsetLCS.cpp b/codebook/9_Else/BitsetLCS.cpp new file mode 100644 index 00000000..57df60da --- /dev/null +++ b/codebook/9_Else/BitsetLCS.cpp @@ -0,0 +1,9 @@ +cin >> n >> m; +for (int i = 1, x; i <= n; ++i) + cin >> x, p[x].set(i); +for (int i = 1, x; i <= m; i++) { + cin >> x, (g = f) |= p[x]; + f.shiftLeftByOne(), f.set(0); + ((f = g - f) ^= g) &= g; +} +cout << f.count() << '\n'; diff --git a/codebook/9_Else/NQueens.cpp b/codebook/9_Else/NQueens.cpp new file mode 100644 index 00000000..cbd3b125 --- /dev/null +++ b/codebook/9_Else/NQueens.cpp @@ -0,0 +1,16 @@ +void solve(vector &ret, int n) { // no sol when n=2,3 + if (n % 6 == 2) { + for (int i = 2; i <= n; i += 2) ret.push_back(i); + ret.push_back(3); ret.push_back(1); + for (int i = 7; i <= n; i += 2) ret.push_back(i); + ret.push_back(5); + } else if (n % 6 == 3) { + for (int i = 4; i <= n; i += 2) ret.push_back(i); + ret.push_back(2); + for (int i = 5; i <= n; i += 2) ret.push_back(i); + ret.push_back(1); ret.push_back(3); + } else { + for (int i = 2; i <= n; i += 2) ret.push_back(i); + for (int i = 1; i <= n; i += 2) ret.push_back(i); + } +} diff --git a/codebook/content.tex b/codebook/content.tex index 7cbd00dd..d65ce582 100644 --- a/codebook/content.tex +++ b/codebook/content.tex @@ -273,6 +273,10 @@ \subsection{Binary Search On Fraction} \lstinputlisting{9_Else/BinarySearchOnFraction.cpp} \subsection{Min Plus Convolution*} % test by Library Checker Min Plus Convolution (Convex and Arbitrary) \lstinputlisting{9_Else/min_plus_convolution.cpp} +\subsection{Bitset LCS} +\lstinputlisting{9_Else/BitsetLCS.cpp} +\subsection{N Queens Problem} +\lstinputlisting{9_Else/NQueens.cpp} \section{Python} \subsection{Misc} \lstinputlisting[language=Python]{11_Python/misc.py}