add: 220125-CN

This commit is contained in:
Lam Haoyin 2022-01-25 19:06:17 +08:00
parent 812d9ac8f8
commit 63a2679a21
No known key found for this signature in database
GPG Key ID: 8C089CB1A2B7544F
2 changed files with 35 additions and 1 deletions

34
2201/220125-CN.cpp Normal file
View File

@ -0,0 +1,34 @@
#include <cstdio>
template<int N>
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));
}

View File

@ -3,4 +3,4 @@ PROJECT(2201)
SET(CMAKE_CXX_STANDARD 23)
ADD_EXECUTABLE(2201 220124.cpp)
ADD_EXECUTABLE(2201 220125-CN.cpp)