add: 220125-CN
This commit is contained in:
parent
812d9ac8f8
commit
63a2679a21
|
|
@ -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));
|
||||
}
|
||||
|
|
@ -3,4 +3,4 @@ PROJECT(2201)
|
|||
|
||||
SET(CMAKE_CXX_STANDARD 23)
|
||||
|
||||
ADD_EXECUTABLE(2201 220124.cpp)
|
||||
ADD_EXECUTABLE(2201 220125-CN.cpp)
|
||||
|
|
|
|||
Loading…
Reference in New Issue