Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ inline std::vector<T> longest_commom_subsequence(const std::vector<T>& first,
const std::vector<T>& second)
{
constexpr int INF = 1e9;
int n = static_cast<int>(first.size()), m = static_cast<int>(second.size());
const int n = static_cast<int>(first.size());
const int m = static_cast<int>(second.size());

std::vector<T> sequence;
std::vector<std::vector<int>> dp(n + 2, std::vector<int>(m + 2, INF));

Expand Down
2 changes: 1 addition & 1 deletion competitive_programming/src/dp/number_of_subsequences.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace dp {
*/
inline int number_of_subsequences(const std::vector<int>& sequence, int MOD)
{
std::size_t n = sequence.size();
const auto n = sequence.size();
long long dp {};

std::unordered_map<int, int> DP;
Expand Down
2 changes: 1 addition & 1 deletion competitive_programming/src/dp/rectangle_cutting.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace dp {
* in such a way that all side lengths remain integers.
* What is the minimum possible number of moves?
*/
inline unsigned rectangle_cutting(unsigned w, unsigned h)
inline unsigned rectangle_cutting(const unsigned w, const unsigned h)
{
constexpr unsigned INF = 1'000'000'000u;
std::vector<std::vector<unsigned>> dp(w + 1, std::vector<unsigned>(h + 1, INF));
Expand Down
2 changes: 1 addition & 1 deletion competitive_programming/src/dp/removing_digits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace dp
* Given an integer n, return the minimum number of steps to reduce it to zero.
* In one step, you can remove any digit from n and subtract it from n.
*/
inline int removing_digits(int n)
inline int removing_digits(const int n)
{
std::vector<int> dp(n + 1);

Expand Down
22 changes: 11 additions & 11 deletions competitive_programming/src/geometry/circle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,32 @@ struct circle

circle(point _c, double _r) : c {_c}, r {_r} {}

double area() const
double area() const
{
return std::acos(-1) * r * r;
}

double chord(double rad) const
double chord(double rad) const
{
return 2 * r * std::sin(rad / 2);
}

double sector(double rad) const
double sector(double rad) const
{
return 0.5 * rad * area() / std::acos(-1);
}

bool intersects(const circle& other) const
bool intersects(const circle& other) const
{
return dist(c, other.c) < r + other.r;
}

bool contains(const point& p) const
bool contains(const point& p) const
{
return dist(c, p) <= r + EPS;
}

std::pair<point, point> getTangentPoint(const point& p) const
std::pair<point, point> getTangentPoint(const point& p) const
{
double d1 = dist(p, c);
double theta = std::asin(r / d1);
Expand All @@ -57,7 +57,7 @@ struct circle
return {p1, p2};
}

std::vector<std::pair<point, point>> getTangentSegs(const circle& other) const
std::vector<std::pair<point, point>> getTangentSegs(const circle& other) const
{
std::vector<std::pair<point, point>> ans;

Expand Down Expand Up @@ -101,7 +101,7 @@ struct circle
}
};

inline circle circumcircle(const point& a, const point& b, const point& c)
inline circle circumcircle(const point& a, const point& b, const point& c)
{
point u = {(b - a).y, -(b - a).x};
point v = {(c - a).y, -(c - a).x};
Expand All @@ -113,14 +113,14 @@ inline circle circumcircle(const point& a, const point& b, const point& c)
return ans;
}

inline int insideCircle(const point& p, const circle& c)
inline int insideCircle(const point& p, const circle& c)
{
if(std::fabs(dist(p, c.c) - c.r) < EPS) return 1;
else if(dist(p, c.c) < c.r) return 0;
return 2; // 0 = inside /1 = border /2 = outside
}

inline circle incircle(const point& p1, const point& p2, const point& p3)
inline circle incircle(const point& p1, const point& p2, const point& p3)
{
double m1 = dist(p2, p3);
double m2 = dist(p1, p3);
Expand All @@ -131,7 +131,7 @@ inline circle incircle(const point& p1, const point& p2, const point& p3)
return {c, r};
}

inline circle minimumCircle(std::vector<point>& p)
inline circle minimumCircle(std::vector<point> p)
{
std::mt19937 rng(std::chrono::steady_clock::now().time_since_epoch().count());

Expand Down
62 changes: 31 additions & 31 deletions competitive_programming/src/geometry/point.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,97 +13,97 @@ struct point
point() : x(), y() {}
point(double _x, double _y) : x {_x}, y {_y} {}

double norm() const
double norm() const
{
return std::hypot(x, y);
}

point normalized() const
point normalized() const
{
return point(x, y) * (1.0 / norm());
}

double angle() const
double angle() const
{
return std::atan2(y, x);
}

double polarAngle() const
double polarAngle() const
{
double a = std::atan2(y, x);
return a < 0 ? a + 2 * std::acos(-1) : a;
}

bool operator<(const point& other) const
bool operator<(const point& other) const noexcept
{
if(std::fabs(x - other.x) > EPS)
return x < other.x;
return y < other.y;
}

bool operator>(const point& other) const
bool operator>(const point& other) const noexcept
{
if(std::fabs(x - other.x) > EPS)
return x > other.x;
return y > other.y;
}

bool operator<=(const point& other) const
bool operator<=(const point& other) const noexcept
{
if(std::fabs(x - other.x) > EPS)
return x < other.x;
return y <= other.y;
}

bool operator>=(const point& other) const
bool operator>=(const point& other) const noexcept
{
if(std::fabs(x - other.x) > EPS)
return x < other.x;
return y >= other.y;
}

bool operator==(const point& other) const
bool operator==(const point& other) const noexcept
{
return std::fabs(x - other.x) < EPS && std::fabs(y - other.y) < EPS;
}

bool operator!=(const point& other) const
bool operator!=(const point& other) const noexcept
{
return !(*this == other);
}

point operator+(const point& other) const
point operator+(const point& other) const noexcept
{
return {x + other.x, y + other.y};
}

point operator-(const point& other) const
point operator-(const point& other) const noexcept
{
return {x - other.x, y - other.y};
}

point& operator+=(const point& other)
point& operator+=(const point& other) noexcept
{
x += other.x;
y += other.y;
return *this;
}

point& operator-=(const point& other)
point& operator-=(const point& other) noexcept
{
x -= other.x;
y -= other.y;
return *this;
}

point& operator*=(double k)
point& operator*=(double k) noexcept
{
x *= k;
y *= k;
return *this;
}

point operator*(double k) const
point operator*(double k) const noexcept
{
return {x * k, y * k};
}
Expand All @@ -120,76 +120,76 @@ struct point
return {x / k, y / k};
}

point operator-() const
point operator-() const noexcept
{
return {-x, -y};
}
};

inline double dist(const point& p1, const point& p2)
inline double dist(const point& p1, const point& p2)
{
return std::hypot(p1.x - p2.x, p1.y - p2.y);
}

inline double inner(const point& p1, const point& p2)
inline double inner(const point& p1, const point& p2) noexcept
{
return p1.x * p2.x + p1.y * p2.y;
}

inline double cross(const point& p1, const point& p2)
inline double cross(const point& p1, const point& p2) noexcept
{
return p1.x * p2.y - p1.y * p2.x;
}

inline bool ccw(const point& p, const point& q, const point& r)
inline bool ccw(const point& p, const point& q, const point& r) noexcept
{
return cross(q - p, r - p) > EPS;
}

inline bool cw(const point& p, const point& q, const point& r)
inline bool cw(const point& p, const point& q, const point& r) noexcept
{
return cross(q - p, r - p) < -EPS;
}

inline bool collinear(const point& p, const point& q, const point& r)
inline bool collinear(const point& p, const point& q, const point& r) noexcept
{
return std::fabs(cross(p - q, r - p)) < EPS;
}

inline point rotate(const point& p, double rad)
inline point rotate(const point& p, double rad)
{
return {p.x * std::cos(rad) - p.y * std::sin(rad), p.x * std::sin(rad) + p.y * std::cos(rad)};
}

inline double angle(const point& a, const point& o, const point& b)
inline double angle(const point& a, const point& o, const point& b)
{
return std::acos(inner(a - o, b - o) / dist(o, a) * dist(o, b));
}

inline point proj(const point& u, const point& v)
inline point proj(const point& u, const point& v)
{
return v * (inner(u, v) / inner(v, v));
}

inline bool between(const point& p, const point& q, const point& r)
inline bool between(const point& p, const point& q, const point& r) noexcept
{
return collinear(p, q, r) && inner(p - q, r - q) <= 0;
}

inline point lineIntersectSeg(const point& p, const point& q, const point& A, const point& B)
inline point lineIntersectSeg(const point& p, const point& q, const point& A, const point& B)
{
double c = cross(A - B, p - q);
double a = cross(A, B);
double b = cross(p, q);
return (p - q) * (a / c) - (A - B) * (b / c);
}

inline bool parallel(const point& a, const point& b)
inline bool parallel(const point& a, const point& b) noexcept
{
return std::fabs(cross(a, b)) < EPS;
}

inline bool segIntersects(const point& a, const point& b, const point& p, const point& q)
inline bool segIntersects(const point& a, const point& b, const point& p, const point& q)
{
if(parallel(a - b, p - q))
return between(a, p, b) || between(a, q, b) || between(p, a, q) || between(p, b, q);
Expand All @@ -199,7 +199,7 @@ inline bool segIntersects(const point& a, const point& b, const point& p, const
return between(a, i, b) && between(p, i, q);
}

inline point closestToLineSegment(const point& p, const point& a, const point& b)
inline point closestToLineSegment(const point& p, const point& a, const point& b)
{
double u = inner(p - a, b - a) / inner(b - a, b - a);
if(u < 0) return a;
Expand Down
Loading
Loading