From 63a2679a217ebcf7344ae6d25d8c8e2c19e2d01a Mon Sep 17 00:00:00 2001 From: Lam Haoyin Date: Tue, 25 Jan 2022 19:06:17 +0800 Subject: [PATCH] add: 220125-CN --- 2201/220125-CN.cpp | 34 ++++++++++++++++++++++++++++++++++ 2201/CMakeLists.txt | 2 +- 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 2201/220125-CN.cpp diff --git a/2201/220125-CN.cpp b/2201/220125-CN.cpp new file mode 100644 index 0000000..4df90fa --- /dev/null +++ b/2201/220125-CN.cpp @@ -0,0 +1,34 @@ +#include + +template +struct AnswerGenerator { + int answer[N + 1] {}; + constexpr AnswerGenerator() : answer() { + answer[0] = answer[1] = 0; + answer[2] = 1; + for (int i = 3; i <= N; ++i) { + answer[i] = (i & 1) ? ((i - 1) / 2 + answer[(i - 1) / 2 + 1]) : (i / 2 + answer[i / 2]); + } + } +}; + +class SolutionGen { +private: + inline static constexpr AnswerGenerator<200> ans; +public: + inline static constexpr int numberOfMatches(int n) { + return ans.answer[n]; + } +}; + +class Solution { +public: + inline static constexpr int numberOfMatches(int n) { + return n - 1; + } +}; + +int main() { + std::printf("%d -> %d\n", 7, SolutionGen::numberOfMatches(7)); + std::printf("%d -> %d\n", 14, SolutionGen::numberOfMatches(14)); +} diff --git a/2201/CMakeLists.txt b/2201/CMakeLists.txt index 1ad5ee4..cacd355 100644 --- a/2201/CMakeLists.txt +++ b/2201/CMakeLists.txt @@ -3,4 +3,4 @@ PROJECT(2201) SET(CMAKE_CXX_STANDARD 23) -ADD_EXECUTABLE(2201 220124.cpp) +ADD_EXECUTABLE(2201 220125-CN.cpp)