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
2 changes: 1 addition & 1 deletion dp/cumulative-sum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ struct CumulativeSum {

explicit CumulativeSum(size_t sz) : data(sz + 1, 0) {}

void add(int k, const T &x) { data[k + 1] += x; }
void add(int k, const T& x) { data[k + 1] += x; }

void build() {
for (int i = 1; i < data.size(); i++) {
Expand Down
4 changes: 2 additions & 2 deletions dp/divide-and-conquer-optimization.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

template <typename T, typename Compare = less<T> >
vector<vector<T> > divide_and_conquer_optimization(
int H, int W, T INF, const function<T(int, int)> &f,
const Compare &comp = Compare()) {
int H, int W, T INF, const function<T(int, int)>& f,
const Compare& comp = Compare()) {
vector<vector<T> > dp(H + 1, vector<T>(W + 1, INF));
dp[0][0] = 0;
for (int i = 1; i <= H; i++) {
Expand Down
2 changes: 1 addition & 1 deletion dp/edit-distance.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
int edit_distance(const string &S, const string &T) {
int edit_distance(const string& S, const string& T) {
const int N = (int)S.size(), M = (int)T.size();
vector<vector<int> > dp(N + 1, vector<int>(M + 1, N + M));
for (int i = 0; i <= N; i++) dp[i][0] = i;
Expand Down
2 changes: 1 addition & 1 deletion dp/knapsack-01-2.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
template <typename T>
T knapsack_01_2(const vector<T> &w, const vector<int> &v, const T &W) {
T knapsack_01_2(const vector<T>& w, const vector<int>& v, const T& W) {
const int N = (int)w.size();
const int sum = accumulate(begin(v), end(v), 0);
vector<T> dp(sum + 1, W + 1);
Expand Down
4 changes: 2 additions & 2 deletions dp/knapsack-01.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
template <typename T, typename Compare = greater<T> >
vector<T> knapsack_01(const vector<int> &w, const vector<T> &v, const int &W,
const T &NG, const Compare &comp = Compare()) {
vector<T> knapsack_01(const vector<int>& w, const vector<T>& v, const int& W,
const T& NG, const Compare& comp = Compare()) {
const int N = (int)w.size();
vector<T> dp(W + 1, NG);
dp[0] = T();
Expand Down
6 changes: 3 additions & 3 deletions dp/knapsack-limitations-2.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "knapsack-limitations.hpp"

template <typename T>
T knapsack_limitations(const vector<T> &w, const vector<T> &m,
const vector<int> &v, const T &W) {
T knapsack_limitations(const vector<T>& w, const vector<T>& m,
const vector<int>& v, const T& W) {
const int N = (int)w.size();
auto v_max = *max_element(begin(v), end(v));
if (v_max == 0) return 0;
Expand All @@ -23,7 +23,7 @@ T knapsack_limitations(const vector<T> &w, const vector<T> &m,
for (int i = 0; i < dp.size(); i++) {
if (dp[i] > W || dp[i] == -1) continue;
T rest = W - dp[i], cost = i;
for (auto &p : ord) {
for (auto& p : ord) {
auto get = min(mb[p], rest / w[p]);
if (get <= 0) continue;
cost += get * v[p];
Expand Down
6 changes: 3 additions & 3 deletions dp/knapsack-limitations.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
template <typename T, typename Compare = greater<T> >
vector<T> knapsack_limitations(const vector<int> &w, const vector<int> &m,
const vector<T> &v, const int &W, const T &NG,
const Compare &comp = Compare()) {
vector<T> knapsack_limitations(const vector<int>& w, const vector<int>& m,
const vector<T>& v, const int& W, const T& NG,
const Compare& comp = Compare()) {
const int N = (int)w.size();
vector<T> dp(W + 1, NG), deqv(W + 1);
dp[0] = T();
Expand Down
4 changes: 2 additions & 2 deletions dp/knapsack.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
template <typename T, typename Compare = greater<T> >
vector<T> knapsack(const vector<int> &w, const vector<T> &v, const int &W,
const T &NG, const Compare &comp = Compare()) {
vector<T> knapsack(const vector<int>& w, const vector<T>& v, const int& W,
const T& NG, const Compare& comp = Compare()) {
const int N = (int)w.size();
vector<T> dp(W + 1, NG);
dp[0] = T();
Expand Down
4 changes: 2 additions & 2 deletions dp/longest-increasing-subsequence.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
template <typename T>
size_t longest_increasing_subsequence(const vector<T> &a, bool strict) {
size_t longest_increasing_subsequence(const vector<T>& a, bool strict) {
vector<T> lis;
for (auto &p : a) {
for (auto& p : a) {
typename vector<T>::iterator it;
if (strict)
it = lower_bound(begin(lis), end(lis), p);
Expand Down
4 changes: 2 additions & 2 deletions dp/monotone-minima.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
template <typename T, typename Compare = less<T> >
vector<pair<int, T> > monotone_minima(int H, int W,
const function<T(int, int)> &f,
const Compare &comp = Compare()) {
const function<T(int, int)>& f,
const Compare& comp = Compare()) {
vector<pair<int, T> > dp(H);
function<void(int, int, int, int)> dfs = [&](int top, int bottom, int left,
int right) {
Expand Down
4 changes: 2 additions & 2 deletions dp/online-offline-dp.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "monotone-minima.hpp"

template <typename T, typename Compare = less<T> >
vector<T> online_offline_dp(int W, const function<T(int, int)> &f,
const Compare &comp = Compare()) {
vector<T> online_offline_dp(int W, const function<T(int, int)>& f,
const Compare& comp = Compare()) {
vector<T> dp(W + 1);
vector<int> isset(W + 1);
int y_base = -1, x_base = -1;
Expand Down
6 changes: 3 additions & 3 deletions geometry/angle.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#include "point.hpp"

namespace geometry {
Real radian_to_degree(const Real &theta) { return theta * 180.0 / PI; }
Real radian_to_degree(const Real& theta) { return theta * 180.0 / PI; }

Real degree_to_radian(const Real &deg) { return deg * PI / 180.0; }
Real degree_to_radian(const Real& deg) { return deg * PI / 180.0; }

// smaller angle of the a-b-c
Real get_smaller_angle(const Point &a, const Point &b, const Point &c) {
Real get_smaller_angle(const Point& a, const Point& b, const Point& c) {
const Point v(a - b), w(c - b);
auto alpha = atan2(imag(v), real(v));
auto beta = atan2(imag(w), real(w));
Expand Down
2 changes: 1 addition & 1 deletion geometry/area.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace geometry {
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_3_A
Real area(const Polygon &p) {
Real area(const Polygon& p) {
int n = (int)p.size();
Real A = 0;
for (int i = 0; i < n; ++i) {
Expand Down
4 changes: 2 additions & 2 deletions geometry/base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const Real PI = acos(static_cast<Real>(-1));

enum { OUT, ON, IN };

inline int sign(const Real &r) { return r <= -EPS ? -1 : r >= EPS ? 1 : 0; }
inline int sign(const Real& r) { return r <= -EPS ? -1 : r >= EPS ? 1 : 0; }

inline bool equals(const Real &a, const Real &b) { return sign(a - b) == 0; }
inline bool equals(const Real& a, const Real& b) { return sign(a - b) == 0; }
} // namespace geometry
2 changes: 1 addition & 1 deletion geometry/ccw.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ constexpr int CLOCKWISE = -1;
constexpr int ONLINE_BACK = +2; // c-a-b
constexpr int ONLINE_FRONT = -2; // a-b-c
constexpr int ON_SEGMENT = 0; // a-c-b
int ccw(const Point &a, Point b, Point c) {
int ccw(const Point& a, Point b, Point c) {
b = b - a, c = c - a;
if (sign(cross(b, c)) == +1) return COUNTER_CLOCKWISE;
if (sign(cross(b, c)) == -1) return CLOCKWISE;
Expand Down
2 changes: 1 addition & 1 deletion geometry/circle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ struct Circle {

Circle() = default;

Circle(const Point &p, const Real &r) : p(p), r(r) {}
Circle(const Point& p, const Real& r) : p(p), r(r) {}
};

using Circles = vector<Circle>;
Expand Down
4 changes: 2 additions & 2 deletions geometry/common_area_cp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace geometry {
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_7_H
Real ca_cp_impl(const Circle &c, const Point &a, const Point &b) {
Real ca_cp_impl(const Circle& c, const Point& a, const Point& b) {
auto va = c.p - a, vb = c.p - b;
Real f = cross(va, vb), ret = 0;
if (sign(f) == 0) return ret;
Expand All @@ -27,7 +27,7 @@ Real ca_cp_impl(const Circle &c, const Point &a, const Point &b) {
return ret;
}

Real common_area_cp(const Circle &c, const Polygon &p) {
Real common_area_cp(const Circle& c, const Polygon& p) {
if (p.size() < 3) return 0;
Real A = 0;
for (int i = 0; i < p.size(); i++) {
Expand Down
2 changes: 1 addition & 1 deletion geometry/contains.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace geometry {
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_3_C
int contains(const Polygon &Q, const Point &p) {
int contains(const Polygon& Q, const Point& p) {
bool in = false;
for (int i = 0; i < Q.size(); i++) {
Point a = Q[i] - p, b = Q[(i + 1) % Q.size()] - p;
Expand Down
2 changes: 1 addition & 1 deletion geometry/convex_hull.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace geometry {
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_4_A
Polygon convex_hull(Polygon &p, bool strict = true) {
Polygon convex_hull(Polygon& p, bool strict = true) {
int n = (int)p.size(), k = 0;
if (n <= 2) return p;
sort(begin(p), end(p), compare_x);
Expand Down
2 changes: 1 addition & 1 deletion geometry/convex_polygon_contains.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "polygon.hpp"

namespace geometry {
int convex_polygon_contains(const Polygon &Q, const Point &p) {
int convex_polygon_contains(const Polygon& Q, const Point& p) {
int N = (int)Q.size();
Point g = (Q[0] + Q[N / 3] + Q[N * 2 / 3]) / 3.0;
if (equals(imag(g), imag(p)) && equals(real(g), real(p))) return IN;
Expand Down
6 changes: 3 additions & 3 deletions geometry/convex_polygon_cut.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
namespace geometry {
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_4_C
// cut with a straight line l and return a convex polygon on the left
Polygon convex_polygon_cut(const Polygon &U, const Line &l) {
Polygon convex_polygon_cut(const Polygon& U, const Line& l) {
Polygon ret;
for (int i = 0; i < U.size(); i++) {
const Point &now = U[i];
const Point &nxt = U[(i + 1) % U.size()];
const Point& now = U[i];
const Point& nxt = U[(i + 1) % U.size()];
auto cf = cross(l.a - now, l.b - now);
auto cs = cross(l.a - nxt, l.b - nxt);
if (sign(cf) >= 0) {
Expand Down
2 changes: 1 addition & 1 deletion geometry/convex_polygon_diameter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace geometry {
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_4_B
pair<int, int> convex_polygon_diameter(const Polygon &p) {
pair<int, int> convex_polygon_diameter(const Polygon& p) {
int N = (int)p.size();
int is = 0, js = 0;
for (int i = 1; i < N; i++) {
Expand Down
2 changes: 1 addition & 1 deletion geometry/cross_point_cc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace geometry {
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_7_E
Points cross_point_cc(const Circle &c1, const Circle &c2) {
Points cross_point_cc(const Circle& c1, const Circle& c2) {
Real d = abs(c1.p - c2.p), r = c1.r + c2.r;
if (sign(d - r) > 0 or sign(d + c1.r - c2.r) < 0) return {};
Real a = acos((norm(c1.r) - norm(c2.r) + norm(d)) / (2 * c1.r * d));
Expand Down
2 changes: 1 addition & 1 deletion geometry/cross_point_cl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace geometry {
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_7_D
Points cross_point_cl(const Circle &c, const Line &l) {
Points cross_point_cl(const Circle& c, const Line& l) {
Point pr = projection(l, c.p);
if (equals(abs(pr - c.p), c.r)) return {pr};
Point e = (l.b - l.a) / abs(l.b - l.a);
Expand Down
2 changes: 1 addition & 1 deletion geometry/cross_point_cs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "segment.hpp"

namespace geometry {
Points cross_point_cs(const Circle &c, const Segment &s) {
Points cross_point_cs(const Circle& c, const Segment& s) {
int num = is_intersect_cs(c, s);
if (num == 0) return {};
if (num == 2) return cross_point_cl(c, s);
Expand Down
2 changes: 1 addition & 1 deletion geometry/cross_point_ll.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "line.hpp"

namespace geometry {
Point cross_point_ll(const Line &l, const Line &m) {
Point cross_point_ll(const Line& l, const Line& m) {
Real A = cross(l.b - l.a, m.b - m.a);
Real B = cross(l.b - l.a, l.b - m.a);
if (equals(abs(A), 0) && equals(abs(B), 0)) return m.a;
Expand Down
2 changes: 1 addition & 1 deletion geometry/distance_ll.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "line.hpp"

namespace geometry {
Real distance_ll(const Line &l, const Line &m) {
Real distance_ll(const Line& l, const Line& m) {
return is_intersect_ll(l, m) ? 0 : distance_lp(l, m.a);
}
} // namespace geometry
2 changes: 1 addition & 1 deletion geometry/distance_lp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "projection.hpp"

namespace geometry {
Real distance_lp(const Line &l, const Point &p) {
Real distance_lp(const Line& l, const Point& p) {
return abs(p - projection(l, p));
}
} // namespace geometry
2 changes: 1 addition & 1 deletion geometry/distance_pp.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "point.hpp"

namespace geometry {
Real distance(const Point &a, const Point &b) { return abs(a - b); }
Real distance(const Point& a, const Point& b) { return abs(a - b); }
} // namespace geometry
2 changes: 1 addition & 1 deletion geometry/distance_sp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "segment.hpp"

namespace geometry {
Real distance_sp(const Segment &s, const Point &p) {
Real distance_sp(const Segment& s, const Point& p) {
Point r = projection(s, p);
if (is_intersect_sp(s, r)) return abs(r - p);
return min(abs(s.a - p), abs(s.b - p));
Expand Down
2 changes: 1 addition & 1 deletion geometry/distance_ss.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace geometry {
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_2_D
Real distance_ss(const Segment &a, const Segment &b) {
Real distance_ss(const Segment& a, const Segment& b) {
if (is_intersect_ss(a, b)) return 0;
return min({distance_sp(a, b.a), distance_sp(a, b.b), distance_sp(b, a.a),
distance_sp(b, a.b)});
Expand Down
2 changes: 1 addition & 1 deletion geometry/is_convex_polygon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace geometry {
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_3_B
bool is_convex_polygon(const Polygon &p) {
bool is_convex_polygon(const Polygon& p) {
int n = (int)p.size();
for (int i = 0; i < n; i++) {
if (ccw(p[(i + n - 1) % n], p[i], p[(i + 1) % n]) == CLOCKWISE)
Expand Down
2 changes: 1 addition & 1 deletion geometry/is_intersect_cl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "line.hpp"

namespace geometry {
bool is_intersect_cl(const Circle &c, const Line &l) {
bool is_intersect_cl(const Circle& c, const Line& l) {
return sign(c.r - distance_lp(l, c.p)) >= 0;
}
} // namespace geometry
2 changes: 1 addition & 1 deletion geometry/is_intersect_cp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "point.hpp"

namespace geometry {
bool is_intersect_cp(const Circle &c, const Point &p) {
bool is_intersect_cp(const Circle& c, const Point& p) {
return equals(abs(p - c.p) - c.r, 0);
}
} // namespace geometry
2 changes: 1 addition & 1 deletion geometry/is_intersect_cs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "segment.hpp"

namespace geometry {
int is_intersect_cs(const Circle &c, const Segment &l) {
int is_intersect_cs(const Circle& c, const Segment& l) {
Point h = projection(l, c.p);
if (sign(norm(h - c.p) - norm(c.r)) > 0) return 0;
auto d1 = abs(c.p - l.a), d2 = abs(c.p - l.b);
Expand Down
2 changes: 1 addition & 1 deletion geometry/is_intersect_ll.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "line.hpp"

namespace geometry {
bool is_intersect_ll(const Line &l, const Line &m) {
bool is_intersect_ll(const Line& l, const Line& m) {
Real A = cross(l.b - l.a, m.b - m.a);
Real B = cross(l.b - l.a, l.b - m.a);
if (equals(abs(A), 0) && equals(abs(B), 0)) return true;
Expand Down
2 changes: 1 addition & 1 deletion geometry/is_intersect_lp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "point.hpp"

namespace geometry {
bool is_intersect_lp(const Line &l, const Point &p) {
bool is_intersect_lp(const Line& l, const Point& p) {
return abs(ccw(l.a, l.b, p)) != 1;
}
} // namespace geometry
2 changes: 1 addition & 1 deletion geometry/is_intersect_ls.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "segment.hpp"

namespace geometry {
bool is_intersect_ls(const Line &l, const Segment &s) {
bool is_intersect_ls(const Line& l, const Segment& s) {
return sign(cross(l.b - l.a, s.a - l.a)) *
sign(cross(l.b - l.a, s.b - l.a)) <=
0;
Expand Down
2 changes: 1 addition & 1 deletion geometry/is_intersect_sp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "segment.hpp"

namespace geometry {
bool is_intersect_sp(const Segment &s, const Point &p) {
bool is_intersect_sp(const Segment& s, const Point& p) {
return ccw(s.a, s.b, p) == ON_SEGMENT;
}
} // namespace geometry
2 changes: 1 addition & 1 deletion geometry/is_intersect_ss.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "segment.hpp"

namespace geometry {
bool is_intersect_ss(const Segment &s, const Segment &t) {
bool is_intersect_ss(const Segment& s, const Segment& t) {
return ccw(s.a, s.b, t.a) * ccw(s.a, s.b, t.b) <= 0 &&
ccw(t.a, t.b, s.a) * ccw(t.a, t.b, s.b) <= 0;
}
Expand Down
Loading
Loading