add: 220409-CN [cpp]

This commit is contained in:
Lam Haoyin 2022-04-09 23:30:37 +08:00
parent acbb036a56
commit a812bd6179
No known key found for this signature in database
GPG Key ID: 8C089CB1A2B7544F
2 changed files with 21 additions and 1 deletions

20
cpp/2204/220409-CN.cpp Normal file
View File

@ -0,0 +1,20 @@
#include <chrono>
#include <numeric>
#include <iostream>
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<std::chrono::milliseconds>(end - start).count() << " ms" << std::endl;
}

View File

@ -3,4 +3,4 @@ PROJECT(2204)
SET(CMAKE_CXX_STANDARD 23)
ADD_EXECUTABLE(2204 220408.cpp)
ADD_EXECUTABLE(2204 220409-CN.cpp)