We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 937230b commit c50ad83Copy full SHA for c50ad83
perm.cpp
@@ -0,0 +1,36 @@
1
+// Permutation
2
+// https://youtu.be/-j02o6__jgs?t=7302
3
+struct Perm : vector<int> {
4
+#define n (int)(size())
5
+#define p (*this)
6
+ Perm(int _n): vector<int>(_n) {
7
+ iota(begin(), end(), 0);
8
+ }
9
+ template<class...Args> Perm(Args...args): vector<int>(args...) {}
10
+ Perm(initializer_list<int> a): vector<int>(a.begin(),a.end()) {}
11
+ Perm operator+(const Perm& a) const {
12
+ Perm r(n);
13
+ for (int i = 0; i < n; ++i) r[i] = p[a[i]];
14
+ return r;
15
16
+ Perm& operator+=(const Perm& a) {
17
+ return *this = (*this)+a;
18
19
+ Perm operator-() const {
20
21
+ for (int i = 0; i < n; ++i) r[p[i]] = i;
22
23
24
+ Perm operator-(const Perm& a) const {
25
+ return *this + -a;
26
27
+ Perm& operator-=(const Perm& a) {
28
+ return *this += -a;
29
30
+ // next permutation
31
+ bool operator++() {
32
+ return next_permutation(begin(),end());
33
34
+#undef n
35
+#undef p
36
+};
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
0 commit comments