-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplates.h
118 lines (106 loc) · 3.03 KB
/
templates.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#pragma once
#include <array>
#include <string>
#include <vector>
using namespace std;
/// \brief 字典树节点
struct TrieNode {
char ch;
array<TrieNode *, 26> nexts = {};
bool end_of_word = false;
unsigned count = 0;
explicit TrieNode(char ch)
: ch(ch) {}
void insert(const string &str);
~TrieNode();
};
/// \brief 高精度整数
class BigInt {
private:
bool positive = true;
vector<unsigned short> vec = {};
[[nodiscard]] unsigned long get_size() const;
unsigned short operator[](unsigned long /*i*/) const;
BigInt(const vector<unsigned short> &vec, bool positive);
vector<unsigned short> operator*(unsigned short n) const;
public:
BigInt(short n);
BigInt(int n);
BigInt(long n);
BigInt(long long n);
BigInt(unsigned short n);
BigInt(unsigned int n);
BigInt(unsigned long n);
BigInt(unsigned long long n);
BigInt(const string &str);
BigInt(const char *str);
BigInt(const BigInt &bi);
BigInt operator+(const BigInt &bi) const;
BigInt operator-(const BigInt &bi) const;
BigInt operator*(const BigInt &bi) const;
BigInt operator/(const BigInt &bi) const;
BigInt operator%(const BigInt &bi) const;
BigInt operator-() const;
BigInt &operator+=(const BigInt &bi);
BigInt &operator-=(const BigInt &bi);
BigInt &operator*=(const BigInt &bi);
BigInt &operator/=(const BigInt &bi);
BigInt &operator%=(const BigInt &bi);
BigInt &operator++();
BigInt &operator--();
BigInt operator++(int);
BigInt operator--(int);
bool operator>(const BigInt &bi) const;
bool operator<(const BigInt &bi) const;
bool operator==(const BigInt &bi) const;
bool operator!=(const BigInt &bi) const;
bool operator>=(const BigInt &bi) const;
bool operator<=(const BigInt &bi) const;
friend ostream &operator<<(ostream &os, const BigInt & /*bi*/);
friend istream &operator>>(istream &is, const BigInt & /*bi*/);
BigInt();
};
/// \brief 分数
class Fraction {
private:
bool positive; ///< 正负
unsigned long long numerator; ///< 分子
unsigned long long denominator;///< 分母
void simplify();
public:
Fraction(bool positive, long long numerator, long long denominator);
Fraction operator+(const Fraction &f) const;
Fraction operator-(const Fraction &f) const;
Fraction operator*(const Fraction &f) const;
Fraction operator/(const Fraction &f) const;
[[nodiscard]] bool is_positive() const;
[[nodiscard]] unsigned long long get_numerator() const;
[[nodiscard]] unsigned long long get_denominator() const;
friend ostream &operator<<(ostream &os, const Fraction &frac);
};
/// \brief 并查集
class UnionFind {
private:
vector<int> parent;
vector<int> rank;
vector<int> size;
public:
explicit UnionFind(int n);
int find(int x);
void unite(int x, int y);
bool same(int x, int y);
int get_size(int x);
unsigned count();
};
/// \brief 矩阵
class Matrix {
private:
vector<vector<int>> mat;
public:
Matrix(int n);
Matrix(const Matrix &m);
Matrix operator*(const Matrix &m) const;
vector<int> &operator[](int i);
const vector<int> &operator[](int i) const;
static Matrix identity(int n);
};