add: 220409-CN [cpp]
This commit is contained in:
parent
acbb036a56
commit
a812bd6179
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
@ -3,4 +3,4 @@ PROJECT(2204)
|
||||||
|
|
||||||
SET(CMAKE_CXX_STANDARD 23)
|
SET(CMAKE_CXX_STANDARD 23)
|
||||||
|
|
||||||
ADD_EXECUTABLE(2204 220408.cpp)
|
ADD_EXECUTABLE(2204 220409-CN.cpp)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue