File tree Expand file tree Collapse file tree 5 files changed +58
-4
lines changed
Expand file tree Collapse file tree 5 files changed +58
-4
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ AtCoder解説放送ライブラリ集
1515| 名前| コード| 説明|
1616| :--| :--| :--|
1717| BIT| [ bit.cpp] ( bit.cpp ) | Binary Indexed Tree (Fenwick Tree)|
18+ | UnionFind| [ uf.cpp] ( uf.cpp ) | Union Find|
1819
1920### 数学
2021| 名前| コード| 説明|
@@ -35,4 +36,6 @@ AtCoder解説放送ライブラリ集
3536### 幾何
3637| 名前| コード| 説明|
3738| :--| :--| :--|
38- | Vector| [ vector.cpp] ( vector.cpp ) | ベクトル(点を扱う際にも使う)|
39+ | 基本| [ geom.cpp] ( geom.cpp ) | 幾何のベース+目次|
40+ | Vector| [ geom/vector.cpp] ( geom/vector.cpp ) | ベクトル(点を扱う際にも使う)|
41+ | Circle| [ geom/circle.cpp] ( geom/circle.cpp ) | 円|
Original file line number Diff line number Diff line change 1+ // Geometry
2+ const double eps = 1e-9 ;
3+ bool equal (double a, double b) { return abs (a-b) < eps;}
4+
5+ [geom/vector]
6+ [geom/circle]
Original file line number Diff line number Diff line change 1+ // Circle
2+ // coding: https://youtu.be/TdR816rqc3s?t=1750
3+ // comment: https://youtu.be/TdR816rqc3s?t=11609
4+ struct Circle {
5+ V o; double r;
6+ Circle (V o=V(), double r=0 ) : o(o), r(r) {}
7+ vector<V> crossPoint (const Circle& c) {
8+ V v = c.o -o;
9+ double l = v.norm ();
10+ if (equal (l, 0 )) return {};
11+ if (equal (l+r+c.r , max ({l,r,c.r })*2 )) {
12+ if (equal (l+r,c.r )) return {o - v*(r/l)};
13+ return {o + v*(r/l)};
14+ }
15+ if (l+r+c.r < max ({l,r,c.r })*2 ) return {};
16+ double x = (l*l + r*r - c.r *c.r ) / (2 *l);
17+ double y = sqrt (r*r - x*x);
18+ V mid = o + v*(x/l);
19+ v = v.rotate90 ();
20+ return {mid + v*(y/l), mid - v*(y/l)};
21+ }
22+ bool isInside (const V& p) const {
23+ return (p-o).norm () < r+eps;
24+ }
25+ };
Original file line number Diff line number Diff line change 1- // vector
1+ // Vector
22// https://youtu.be/UWbGRhF3Ozw?t=9564
3- const double eps = 1e-9 ;
43struct V {
54 double x, y;
65 V (double x=0 , double y=0 ): x(x), y(y) {}
@@ -16,7 +15,7 @@ struct V {
1615 double cross (const V& v) const { return x*v.y - v.x *y;}
1716 double norm2 () const { return x*x + y*y;}
1817 double norm () const { return sqrt (norm2 ());}
19-
18+ V rotate90 () const { return V (y, -x);}
2019 int ort () const { // orthant
2120 if (abs (x) < eps && abs (y) < eps) return 0 ;
2221 if (y > 0 ) return x>0 ? 1 : 2 ;
Original file line number Diff line number Diff line change 1+ // UnionFind
2+ // coding: https://youtu.be/TdR816rqc3s?t=726
3+ // comment: https://youtu.be/TdR816rqc3s?t=6822
4+ struct UnionFind {
5+ vector<int > d;
6+ UnionFind (int n=0 ): d(n,-1 ) {}
7+ int find (int x) {
8+ if (d[x] < 0 ) return x;
9+ return d[x] = find (d[x]);
10+ }
11+ bool unite (int x, int y) {
12+ x = find (x); y = find (y);
13+ if (x == y) return false ;
14+ if (d[x] > d[y]) swap (x,y);
15+ d[x] += d[y];
16+ d[y] = x;
17+ return true ;
18+ }
19+ bool same (int x, int y) { return find (x) == find (y);}
20+ int size (int x) { return -d[find (x)];}
21+ };
You can’t perform that action at this time.
0 commit comments