From a812bd6179f8c74229554a5c934b32aec980d402 Mon Sep 17 00:00:00 2001 From: Lam Haoyin Date: Sat, 9 Apr 2022 23:30:37 +0800 Subject: [PATCH] add: 220409-CN [cpp] --- cpp/2204/220409-CN.cpp | 20 ++++++++++++++++++++ cpp/2204/CMakeLists.txt | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 cpp/2204/220409-CN.cpp diff --git a/cpp/2204/220409-CN.cpp b/cpp/2204/220409-CN.cpp new file mode 100644 index 0000000..7c7291f --- /dev/null +++ b/cpp/2204/220409-CN.cpp @@ -0,0 +1,20 @@ +#include +#include +#include + +class Solution { +public: + static bool reachingPoints(int sx, int sy, int tx, int ty) { + for (; tx != ty && tx > sx && ty > sy; *(tx > ty ? &tx : &ty) = std::abs(tx - ty)) + if (tx == sx && ty == sy) + return true; + return (tx == sx && ty > sy && !((ty - sy) % sx)) || (ty == sy && tx > sx && !((tx - sx) % sy)); + } +}; + +int main() { + const auto start = std::chrono::steady_clock::now(); + std::cout << Solution::reachingPoints(1, 6, 11, 10) << std::endl; + const auto end = std::chrono::steady_clock::now(); + std::cout << std::chrono::duration_cast(end - start).count() << " ms" << std::endl; +} diff --git a/cpp/2204/CMakeLists.txt b/cpp/2204/CMakeLists.txt index ca239ac..c2261e2 100644 --- a/cpp/2204/CMakeLists.txt +++ b/cpp/2204/CMakeLists.txt @@ -3,4 +3,4 @@ PROJECT(2204) SET(CMAKE_CXX_STANDARD 23) -ADD_EXECUTABLE(2204 220408.cpp) +ADD_EXECUTABLE(2204 220409-CN.cpp)