Skip to content

Commit 8a9447b

Browse files
authored
Format source code (indy256#150)
1 parent 6792012 commit 8a9447b

File tree

269 files changed

+2123
-2065
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

269 files changed

+2123
-2065
lines changed

Diff for: .clang-format

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
BasedOnStyle: Google
3+
IndentWidth: 4
4+
ColumnLimit: 120
5+
6+
---
7+
Language: Cpp
8+
AllowShortBlocksOnASingleLine: false
9+
AllowShortIfStatementsOnASingleLine: false
10+
AllowShortLoopsOnASingleLine: false
11+
AllowShortFunctionsOnASingleLine: Inline
12+
13+
---
14+
Language: Java

Diff for: .github/workflows/main.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: clang-format
2+
3+
on: [push]
4+
5+
jobs:
6+
check-clang-format:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2
10+
- name: run clang-format
11+
run: |
12+
source_files=$(find . -type f -name "*.cpp" -o -name "*.h" -o -name "*.java")
13+
diff -u <(cat $source_files) <(clang-format $source_files)

Diff for: cpp/backtrack/mis.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ using namespace std;
44
#ifdef _MSC_VER
55
int __builtin_ctzll(unsigned long long x) {
66
int bit = 0;
7-
while (bit < 64 && (x & (1LL << bit)) == 0) ++bit;
7+
while (bit < 64 && (x & (1LL << bit)) == 0)
8+
++bit;
89
return bit;
910
}
1011
int __builtin_popcountll(unsigned long long x) {
1112
int bits = 0;
12-
for (; x; x &= x - 1, ++bits);
13+
for (; x; x &= x - 1, ++bits)
14+
;
1315
return bits;
1416
}
1517
#endif

Diff for: cpp/combinatorics/enumerating_combinations.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ bool next_combination(vector<int> &comb, int n) {
1818
int main() {
1919
vector<int> comb{0, 1, 2};
2020
do {
21-
for (int v : comb) cout << v + 1 << " ";
21+
for (int v : comb)
22+
cout << v + 1 << " ";
2223
cout << endl;
2324
} while (next_combination(comb, 5));
2425
}

Diff for: cpp/geometry/angle_area_orientation_sort_rotation_perpendicular.cpp

+8-7
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ ll double_signed_area(const vector<int> &x, const vector<int> &y) {
2121
int n = x.size();
2222
ll area = 0;
2323
for (int i = 0, j = n - 1; i < n; j = i++) {
24-
area += (ll) (x[i] - x[j]) * (y[i] + y[j]); // area += (long) x[i] * y[j] - (long) x[j] * y[i];
24+
area += (ll)(x[i] - x[j]) * (y[i] + y[j]); // area += (long) x[i] * y[j] - (long) x[j] * y[i];
2525
}
2626
return area;
2727
}
@@ -50,10 +50,12 @@ struct Point {
5050
bool operator<(const Point &o) const {
5151
bool up1 = y > 0 || (y == 0 && x >= 0);
5252
bool up2 = o.y > 0 || (o.y == 0 && o.x >= 0);
53-
if (up1 != up2) return up1;
54-
ll cmp = (ll) o.x * y - (ll) o.y * x;
55-
if (cmp != 0) return cmp < 0;
56-
return (ll) x * x + (ll) y * y < (ll) o.x * o.x + (ll) o.y * o.y;
53+
if (up1 != up2)
54+
return up1;
55+
ll cmp = (ll)o.x * y - (ll)o.y * x;
56+
if (cmp != 0)
57+
return cmp < 0;
58+
return (ll)x * x + (ll)y * y < (ll)o.x * o.x + (ll)o.y * o.y;
5759
// return atan2(y, x) < atan2(o.y, o.x);
5860
}
5961
};
@@ -71,5 +73,4 @@ Line perpendicular(Line line, ll x, ll y) {
7173
}
7274

7375
// usage example
74-
int main() {
75-
}
76+
int main() {}

Diff for: cpp/geometry/convex_hull.cpp

+4-8
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ struct point {
99
};
1010

1111
bool isNotRightTurn(const point &a, const point &b, const point &c) {
12-
long long cross = (long long) (a.x - b.x) * (c.y - b.y) - (long long) (a.y - b.y) * (c.x - b.x);
13-
long long dot = (long long) (a.x - b.x) * (c.x - b.x) + (long long) (a.y - b.y) * (c.y - b.y);
12+
long long cross = (long long)(a.x - b.x) * (c.y - b.y) - (long long)(a.y - b.y) * (c.x - b.x);
13+
long long dot = (long long)(a.x - b.x) * (c.x - b.x) + (long long)(a.y - b.y) * (c.y - b.y);
1414
return cross < 0 || (cross == 0 && dot <= 0);
1515
}
1616

@@ -30,13 +30,9 @@ vector<point> convex_hull(vector<point> points) {
3030

3131
// usage example
3232
int main() {
33-
vector<point> hull1 = convex_hull({{0, 0},
34-
{3, 0},
35-
{0, 3},
36-
{1, 1}});
33+
vector<point> hull1 = convex_hull({{0, 0}, {3, 0}, {0, 3}, {1, 1}});
3734
cout << (3 == hull1.size()) << endl;
3835

39-
vector<point> hull2 = convex_hull({{0, 0},
40-
{0, 0}});
36+
vector<point> hull2 = convex_hull({{0, 0}, {0, 0}});
4137
cout << (1 == hull2.size()) << endl;
4238
}

Diff for: cpp/geometry/diameter.cpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,6 @@ double diameter(const vector<point> &p) {
5656

5757
// usage example
5858
int main() {
59-
double d = diameter({{0, 0},
60-
{3, 0},
61-
{0, 3},
62-
{1, 1}});
59+
double d = diameter({{0, 0}, {3, 0}, {0, 3}, {1, 1}});
6360
cout << d << endl;
6461
}

Diff for: cpp/geometry/dynamic_upper_envelope.cpp

+9-5
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ struct LineContainer : multiset<Line, less<>> {
2222
// (for doubles, use inf = 1/.0, div(a,b) = a/b)
2323
const ll inf = numeric_limits<ll>::max();
2424

25-
ll div(ll a, ll b) { // floored division
25+
ll div(ll a, ll b) { // floored division
2626
return a / b - ((a ^ b) < 0 && a % b);
2727
}
2828

@@ -31,15 +31,19 @@ struct LineContainer : multiset<Line, less<>> {
3131
x->p = inf;
3232
return false;
3333
}
34-
if (x->a == y->a) x->p = x->b > y->b ? inf : -inf;
35-
else x->p = div(y->b - x->b, x->a - y->a);
34+
if (x->a == y->a)
35+
x->p = x->b > y->b ? inf : -inf;
36+
else
37+
x->p = div(y->b - x->b, x->a - y->a);
3638
return x->p >= y->p;
3739
}
3840

3941
void add_line(ll a, ll b) {
4042
auto z = insert({a, b, 0}), y = z++, x = y;
41-
while (isect(y, z)) z = erase(z);
42-
if (x != begin() && isect(--x, y)) isect(x, erase(y));
43+
while (isect(y, z))
44+
z = erase(z);
45+
if (x != begin() && isect(--x, y))
46+
isect(x, erase(y));
4347
while ((y = x) != begin() && (--x)->p >= y->p)
4448
isect(x, erase(y));
4549
}

Diff for: cpp/geometry/find_segments_intersection.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ struct segment {
1818
pii a, b;
1919
int id;
2020

21-
segment(pii a, pii b, int id) :
22-
a(std::move(a)), b(std::move(b)), id(id) {
23-
}
21+
segment(pii a, pii b, int id) : a(std::move(a)), b(std::move(b)), id(id) {}
2422

2523
bool operator<(const segment &o) const {
2624
if (a.first < o.a.first) {

Diff for: cpp/geometry/li_chao_tree.cpp

+4-12
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ using T = long long;
99
struct Line {
1010
T a, d;
1111

12-
T eval(T x) {
13-
return a * x + d;
14-
}
12+
T eval(T x) { return a * x + d; }
1513
};
1614

1715
struct Node {
@@ -63,17 +61,11 @@ struct LiChaoTree {
6361
T maxx;
6462
Node *root;
6563

66-
LiChaoTree(T minx, T maxx) : minx(minx), maxx(maxx) {
67-
root = new Node({0, numeric_limits<T>::max() / 2});
68-
}
64+
LiChaoTree(T minx, T maxx) : minx(minx), maxx(maxx) { root = new Node({0, numeric_limits<T>::max() / 2}); }
6965

70-
void add_line(Line line) {
71-
root->add_line(line, minx, maxx + 1);
72-
}
66+
void add_line(Line line) { root->add_line(line, minx, maxx + 1); }
7367

74-
T get_min(T x) {
75-
return root->get_min(x, minx, maxx + 1);
76-
}
68+
T get_min(T x) { return root->get_min(x, minx, maxx + 1); }
7769
};
7870

7971
// usage example

Diff for: cpp/geometry/point_classification.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ using namespace std;
44

55
using ll = long long;
66

7-
enum class Position {
8-
Left, Right, Behind, Beyond, Origin, Destionation, Between
9-
};
7+
enum class Position { Left, Right, Behind, Beyond, Origin, Destionation, Between };
108

119
// Classifies position of point p against vector a
1210
Position classify(ll px, ll py, ll ax, ll ay) {
@@ -33,5 +31,4 @@ Position classify(ll px, ll py, ll ax, ll ay) {
3331
}
3432

3533
// usage example
36-
int main() {
37-
}
34+
int main() {}

Diff for: cpp/geometry/point_in_polygon.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,18 @@ int pointInPolygon(int qx, int qy, const vector<int> &x, const vector<int> &y) {
99
int cnt = 0;
1010
for (int i = 0, j = n - 1; i < n; j = i++) {
1111
if (y[i] == qy && (x[i] == qx || (y[j] == qy && (x[i] <= qx || x[j] <= qx) && (x[i] >= qx || x[j] >= qx))))
12-
return 0; // boundary
12+
return 0; // boundary
1313
if ((y[i] > qy) != (y[j] > qy)) {
14-
ll det = ((ll) x[i] - qx) * ((ll) y[j] - qy) - ((ll) x[j] - qx) * ((ll) y[i] - qy);
14+
ll det = ((ll)x[i] - qx) * ((ll)y[j] - qy) - ((ll)x[j] - qx) * ((ll)y[i] - qy);
1515
if (det == 0)
16-
return 0; // boundary
16+
return 0; // boundary
1717
if ((det > 0) != (y[j] > y[i]))
1818
++cnt;
1919
}
2020
}
2121
return cnt % 2 == 0 ? -1 /* exterior */ : 1 /* interior */;
2222
}
2323

24-
2524
// usage example
2625
int main() {
2726
vector<int> x{0, 0, 2, 2};

Diff for: cpp/geometry/point_to_segment_distance.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,14 @@ double point_to_segment_distance(int x, int y, int x1, int y1, int x2, int y2) {
1919
return fastHypot(px, py);
2020
if (dotProduct >= squaredLength)
2121
return fastHypot(px - dx, py - dy);
22-
double q = (double) dotProduct / squaredLength;
22+
double q = (double)dotProduct / squaredLength;
2323
return fastHypot(px - q * dx, py - q * dy);
2424
}
2525

2626
double point_to_line_distance(ll x, ll y, ll a, ll b, ll c) {
2727
return abs(a * x + b * y + c) / fastHypot(a, b);
2828
}
2929

30-
3130
// usage example
3231
int main() {
3332
cout << fixed << setprecision(10);

Diff for: cpp/geometry/segments_intersection.cpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <bits/stdc++.h>
2+
23
#include <optional>
34

45
using namespace std;
@@ -14,8 +15,8 @@ bool is_cross_intersect(ll x1, ll y1, ll x2, ll y2, ll x3, ll y3, ll x4, ll y4)
1415
}
1516

1617
bool is_cross_or_touch_intersect(ll x1, ll y1, ll x2, ll y2, ll x3, ll y3, ll x4, ll y4) {
17-
if (max(x1, x2) < min(x3, x4) || max(x3, x4) < min(x1, x2)
18-
|| max(y1, y2) < min(y3, y4) || max(y3, y4) < min(y1, y2))
18+
if (max(x1, x2) < min(x3, x4) || max(x3, x4) < min(x1, x2) || max(y1, y2) < min(y3, y4) ||
19+
max(y3, y4) < min(y1, y2))
1920
return false;
2021
ll z1 = (x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1);
2122
ll z2 = (x2 - x1) * (y4 - y1) - (y2 - y1) * (x4 - x1);
@@ -34,17 +35,17 @@ optional<pair<double, double>> get_lines_intersection(ll x1, ll y1, ll x2, ll y2
3435
ll det = a1 * b2 - a2 * b1;
3536
if (det == 0)
3637
return {};
37-
double x = -(c1 * b2 - c2 * b1) / (double) det;
38-
double y = -(a1 * c2 - a2 * c1) / (double) det;
38+
double x = -(c1 * b2 - c2 * b1) / (double)det;
39+
double y = -(a1 * c2 - a2 * c1) / (double)det;
3940
return optional{make_pair(x, y)};
4041
}
4142

4243
// usage example
4344
int main() {
4445
optional<pair<double, double>> intersection = get_lines_intersection(0, 0, 4, 2, 2, -1, 2, 5);
45-
cout << (bool) intersection << endl;
46+
cout << (bool)intersection << endl;
4647
cout << intersection->first << " " << intersection->second << endl;
4748

4849
optional<pair<double, double>> no_intersection = get_lines_intersection(0, 0, 0, 1, 1, 0, 1, 1);
49-
cout << (bool) no_intersection << endl;
50+
cout << (bool)no_intersection << endl;
5051
}

Diff for: cpp/graphs/cycle_detection.cpp

+6-8
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ vector<int> find_cycle(const vector<vector<int>> &graph) {
2424
vector<int> color(n);
2525
vector<int> next(n);
2626
for (int u = 0; u < n; u++) {
27-
if (color[u] != 0) continue;
27+
if (color[u] != 0)
28+
continue;
2829
int cycleStart = dfs(graph, u, color, next);
2930
if (cycleStart != -1) {
3031
vector<int> cycle;
@@ -41,17 +42,14 @@ vector<int> find_cycle(const vector<vector<int>> &graph) {
4142

4243
// usage example
4344
int main() {
44-
vector<vector<int>> graph{{1},
45-
{2},
46-
{0}};
45+
vector<vector<int>> graph{{1}, {2}, {0}};
4746
auto cycle = find_cycle(graph);
4847
cout << cycle.size() << endl;
49-
for (int x:cycle) cout << x << " ";
48+
for (int x : cycle)
49+
cout << x << " ";
5050
cout << endl;
5151

52-
graph = {{1},
53-
{2},
54-
{}};
52+
graph = {{1}, {2}, {}};
5553
cycle = find_cycle(graph);
5654
cout << cycle.size() << endl;
5755
}

Diff for: cpp/graphs/dfs/strongly_connected_components.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -50,26 +50,26 @@ vector<vector<int>> scc_graph(const vector<vector<int>> &graph, const vector<vec
5050
unordered_set<long long> edges;
5151
for (int u = 0; u < graph.size(); u++)
5252
for (int v : graph[u])
53-
if (comp[u] != comp[v] && edges.insert(((long long) comp[u] << 32) + comp[v]).second)
53+
if (comp[u] != comp[v] && edges.insert(((long long)comp[u] << 32) + comp[v]).second)
5454
g[comp[u]].push_back(comp[v]);
5555
return g;
5656
}
5757

5858
// usage example
5959
int main() {
60-
vector<vector<int>> graph = {{1},
61-
{0},
62-
{0, 1}};
60+
vector<vector<int>> graph = {{1}, {0}, {0, 1}};
6361

6462
vector<vector<int>> components = scc(graph);
65-
for (auto &component: components) {
66-
for (int v:component) cout << v << " ";
63+
for (auto &component : components) {
64+
for (int v : component)
65+
cout << v << " ";
6766
cout << endl;
6867
}
6968

7069
vector<vector<int>> sg = scc_graph(graph, components);
71-
for (auto &a: sg) {
72-
for (int v : a) cout << v << " ";
70+
for (auto &a : sg) {
71+
for (int v : a)
72+
cout << v << " ";
7373
cout << endl;
7474
}
7575
}

Diff for: cpp/graphs/dfs/topological_sort.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,11 @@ vector<int> topological_sort(const vector<vector<int>> &graph) {
2525

2626
// usage example
2727
int main() {
28-
vector<vector<int>> g = {{0},
29-
{},
30-
{0, 1}};
28+
vector<vector<int>> g = {{0}, {}, {0, 1}};
3129

3230
vector<int> order = topological_sort(g);
3331

34-
for (int v : order) cout << v << " ";
32+
for (int v : order)
33+
cout << v << " ";
3534
cout << endl;
3635
}

Diff for: cpp/graphs/flows/global_min_cut_stoer_wagner.cpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,10 @@ pair<int, vector<int>> min_cut(vector<vector<int>> &cap) {
4747

4848
// usage example
4949
int main() {
50-
vector<vector<int>> capacity{{0, 1, 1, 0},
51-
{1, 0, 1, 1},
52-
{1, 1, 0, 1},
53-
{0, 1, 1, 0}};
54-
auto[cap, cut] = min_cut(capacity);
50+
vector<vector<int>> capacity{{0, 1, 1, 0}, {1, 0, 1, 1}, {1, 1, 0, 1}, {0, 1, 1, 0}};
51+
auto [cap, cut] = min_cut(capacity);
5552
cout << cap << endl;
56-
for (int v:cut) cout << v << " ";
53+
for (int v : cut)
54+
cout << v << " ";
5755
cout << endl;
5856
}

0 commit comments

Comments
 (0)