Skip to content

Commit 180a2ce

Browse files
committed
Formatação dos códigos.
1 parent af861d5 commit 180a2ce

18 files changed

+96
-76
lines changed

.clang-format

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ BreakBeforeBinaryOperators: None
3636
BreakBeforeBraces: Attach
3737
BreakBeforeTernaryOperators: true
3838
BreakConstructorInitializersBeforeComma: false
39-
ColumnLimit: 72
39+
ColumnLimit: 71
4040
CommentPragmas: '^ IWYU pragma:'
4141
ConstructorInitializerAllOnOneLineOrOnePerLine: false
4242
ConstructorInitializerIndentWidth: 4

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
}
6565
,
6666
"editor.rulers": [
67-
72
67+
71
6868
],
6969
"C_Cpp.errorSquiggles": "Disabled"
7070
}

TUTORIAL.md

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,41 @@
1-
# Formatter
1+
# Formatação do código
22

3-
## Install Vs Code extension (maybe this is not necessary)
4-
https://marketplace.visualstudio.com/items?itemName=xaver.clang-format
5-
6-
change formatter to use this one
3+
Usaremos clang-format.
74

8-
## Install Clang-format on linux
5+
## Instalação no linux
96

107
```bash
118
sudo apt install clang-format
129
```
1310

14-
## generate clang style based on LLVM style for example and place the file at root of the project
11+
## Gerando um estilo
1512

16-
```
13+
Na raiz do projeto, rode o comando abaixo para gerar um estilo basedo no LLVM.
14+
Altere depois o tamanho da coluna para 71, para caber o código em duas páginas
15+
no notebook.
16+
17+
```bash
1718
clang-format -style=LLVM -dump-config > .clang-format
1819
```
1920

20-
## on each .cpp file, run this command to format it (if vscode is configured)
21+
## Para formatar todos os códigos do projeto
22+
23+
Rode o seguinte comando na raiz do projeto.
2124

2225
```bash
23-
Ctrl + Shift + I
26+
find . -regex '.*\.\(cpp\|hpp\|cc\|cxx\)' -exec clang-format -style=file -i {} \;
2427
```
2528

26-
## Format all files with clang. In the root, run this command.
29+
## Instalar extensão para seu uso no vscode (caso use vscode)
30+
31+
https://marketplace.visualstudio.com/items?itemName=xaver.clang-format
32+
33+
Configure a extensão no VsCode.
34+
35+
Para formater um arquivo, com ele aberto, use a seguinte combinação de
36+
teclas.
2737

2838
```bash
29-
find . -regex '.*\.\(cpp\|hpp\|cc\|cxx\)' -exec clang-format -style=file -i {} \;
30-
```
39+
Ctrl + Shift + I
40+
```
41+

code/estruturas/Polyce.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
// https://codeforces.com/blog/entry/11080
32

43
#include <bits/stdc++.h>
@@ -32,10 +31,11 @@ void newVector() {
3231
// funciona como um vector, mas consegue algo a mais: (log(n))
3332
rope<int> v;
3433
rope<int>::iterator it;
35-
int l, r; // segmento
36-
rope<int> cur = v.substr(l, r - l + 1); // copia um segmento do vector
37-
v.erase(l, r - l + 1); // apaga um segmento
38-
v.insert(v.mutable_begin(), cur); // insere um segmento
34+
int l, r; // segmento
35+
rope<int> cur =
36+
v.substr(l, r - l + 1); // copia um segmento do vector
37+
v.erase(l, r - l + 1); // apaga um segmento
38+
v.insert(v.mutable_begin(), cur); // insere um segmento
3939
for (it = cur.mutable_begin(); it != cur.mutable_end(); it++)
4040
cout << *it << " "; // percorre ele
4141
}

code/estruturas/fenwick_tree2D.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
#define MAXC 3001
33
ll ft[MAXL][MAXC];
44
int L, C;
5-
// update(x,y,v) incrementa v na posicao (x,y) .: M[x][y] += v em
6-
// O(log(N))
5+
// update(x,y,v) incrementa v na posicao (x,y)
6+
// .: M[x][y] += v em O(log(N))
77
void update(int x, int y, int v) {
88
for (; x <= L; x += x & -x)
99
for (int yy = y; yy <= C; yy += yy & -yy)
@@ -24,13 +24,12 @@ ll query(int x, int y) {
2424
}
2525

2626
// query(x1,y1,x2,y2) retorna o somatorio da submatriz definida por
27-
// (x1,x1) -- (x2,y2) .: sum += M[i][j] para todo x1 <= i <= x2 e y1
28-
// <= j <= y2, em O(log(N))
27+
// (x1,x1) -- (x2,y2) .: sum += M[i][j] para todo x1 <= i <= x2 e
28+
// y1 <= j <= y2, em O(log(N))
2929
ll query(int x1, int y1, int x2, int y2) {
3030
return query(x2, y2) - query(x2, y1 - 1) - query(x1 - 1, y2) +
3131
query(x1 - 1, y1 - 1);
3232
}
3333

3434
// A ideia de atualizar um intervalo (submatriz) e consultar um
35-
// elemento (i,j) tambem sao validos
36-
int main() { return 0; }
35+
// elemento (i,j) tambem sao validos

code/estruturas/segment_tree_sum_lazy.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RSQ agora com queries e updates em intervalos. Precisa de Lazy
22
// Propagation. Array A[] deve ser indexado em 0. Nem sempre o array
3-
// que sera modificado armazena apenas um valor. Nesse caso usamos
3+
// que sera modificado armazena apenas um valor, nesse caso usamos
44
// struct para representar cada no.
55
#define MAXN 500000
66
ll A[MAXN], tree[4 * MAXN], lazy[4 * MAXN];

code/geometria/convexhull.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
/*Encontra o convex hull de um conjunto de pontos.
1+
/*Encontra o convex hull de um conjunto de pontos em O(NlogN)
22
pivot: Ponto base para a criacao do convex hull;
33
radial_lt(): Ordena os pontos em sentido anti-horario (ccw).
44
Input: Conjunto de pontos 2D;
55
Output: Conjunto de pontos do convex hull, no sentido anti-horario;
66
7-
(1)Se for preciso manter pontos colineares na borda do convex hull, essa
7+
(1)Se for preciso manter pontos colineares na borda do convex hull,
8+
essa
89
parte evita que eles sejam removidos;
910
*/
1011

@@ -43,4 +44,4 @@ vector<point> convexhull(vector<point> &T) {
4344
tam++;
4445
}
4546
return U;
46-
}
47+
}

code/geometria/geometria2d-funcoes.cpp

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ double arg(point b, point a, point c) {
6767
return atan2(cross(u, v), dot(u, v));
6868
}
6969

70-
////////////////////////////////////////////////////////////////
71-
////////Segmentos, Retas
72-
/////////////////
70+
//////////////////////////////////////////////////////////////////////
71+
///////////////////////// Segmentos, Retas /////////////////////////
72+
//////////////////////////////////////////////////////////////////////
7373

7474
// Determina se P esta entre o segmento fechado [A,B], inclusive
7575
bool between(point p, point a, point b) {
@@ -120,9 +120,9 @@ bool seg_intersect(point a, point b, point c, point d) {
120120
return false;
121121
}
122122

123-
/* Encontra a interseccao das retas (p-q) e (r-s) assumindo que existe
124-
* apenas 1 intereccao. Se for entre segmentos, verificar se interseptam
125-
* primeiro. */
123+
// Encontra a interseccao das retas (p-q) e (r-s) assumindo que existe
124+
// apenas 1 intereccao. Se for entre segmentos, verificar se
125+
// interseptam primeiro.
126126
point line_intersect(point p, point q, point r, point s) {
127127
point a = q - p, b = s - r, c = point(cross(p, q), cross(r, s));
128128
double x = cross(point(a.x, b.x), c);
@@ -131,17 +131,20 @@ point line_intersect(point p, point q, point r, point s) {
131131
}
132132

133133
// determine if lines from a to b and c to d are parallel or collinear
134-
bool LinesParallel(point a, point b, point c, point d) { // Nao testado
134+
bool LinesParallel(point a, point b, point c, point d) { //! Nao
135+
//! testado
135136
return fabs(cross(b - a, c - d)) < EPS;
136137
}
137-
bool LinesCollinear(point a, point b, point c, point d) { // Nao testado
138-
return LinesParallel(a, b, c, d) && fabs(cross(a - b, a - c)) < EPS &&
138+
bool LinesCollinear(point a, point b, point c,
139+
point d) { //! Nao testado
140+
return LinesParallel(a, b, c, d) &&
141+
fabs(cross(a - b, a - c)) < EPS &&
139142
fabs(cross(c - d, c - a)) < EPS;
140143
}
141144

142-
//////////////////////////
143-
// Triangulos
144-
/////////////////////////
145+
//////////////////////////////////////////////////////////////////////
146+
//////////////////////////// Triangulos ////////////////////////////
147+
//////////////////////////////////////////////////////////////////////
145148

146149
bool pointInTriangle(point p, point a, point b, point c) {
147150
// TODO
@@ -161,9 +164,9 @@ double area_heron(double a, double b, double c) {
161164
(a + (b - c)) / 16.0);
162165
}
163166

164-
//////////////////////////
165-
// Circulos
166-
/////////////////////////
167+
//////////////////////////////////////////////////////////////////////
168+
//////////////////////////// Circulos //////////////////////////////
169+
//////////////////////////////////////////////////////////////////////
167170

168171
bool pointInCircle(point p, point c, double radius) {
169172
// Todo
@@ -194,9 +197,10 @@ double spherical_distance(double lt1, double lo1, double lt2,
194197
return r * acos(sin(a) * sin(b) + cos(a) * cos(b) * cos(c));
195198
}
196199

197-
//////////////////////////
198-
// Planos
199-
/////////////////////////
200+
//////////////////////////////////////////////////////////////////////
201+
///////////////////////////// Planos ///////////////////////////////
202+
//////////////////////////////////////////////////////////////////////
203+
200204
// Distancia entre (x,y,z) e plano ax+by+cz=d
201205
double distancePointPlane(double x, double y, double z, double a,
202206
double b, double c, double d) {
@@ -211,7 +215,9 @@ struct circle {
211215
circle(cxpt c, double r) : c(c), r(r) {}
212216
circle() {}
213217
};
214-
double cross(const cxpt &a, const cxpt &b) { return imag(conj(a) * b); }
218+
double cross(const cxpt &a, const cxpt &b) {
219+
return imag(conj(a) * b);
220+
}
215221
double dot(const cxpt &a, const cxpt &b) { return real(conj(a) * b); }
216222

217223
// Area da interseccao de dois circulos

code/geometria/geometria3d-funcoes.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ inline double det(double a11, double a12, double a13, double a21,
3636
double a22, double a23, double a31, double a32,
3737
double a33) {
3838

39-
return a11 * det(a22, a23, a32, a33) - a12 * det(a21, a23, a31, a33) +
40-
a13 * det(a21, a22, a31, a32);
39+
return a11 * det(a22, a23, a32, a33) -
40+
a12 * det(a21, a23, a31, a33) + a13 * det(a21, a22, a31, a32);
4141
}
4242
inline double det(const PT &a, const PT &b, const PT &c) {
4343
return det(a.x, a.y, a.z, b.x, b.y, b.z, c.x, c.y, c.z);
@@ -238,8 +238,8 @@ double polyhedronVol(vector<vector<PT>> poly) {
238238
cent = cent * (1.0 / (poly.size() * 3));
239239
double v = 0;
240240
for (i = 0; i < poly.size(); i++)
241-
v += fabs(
242-
signedTetrahedronVol(cent, poly[i][0], poly[i][1], poly[i][2]));
241+
v += fabs(signedTetrahedronVol(cent, poly[i][0], poly[i][1],
242+
poly[i][2]));
243243
return v;
244244
}
245245

@@ -341,7 +341,8 @@ int cross(const line &l, const plane &pl, PT &res) {
341341
return 1;
342342
}
343343

344-
bool cross(const plane &p1, const plane &p2, const plane &p3, PT &res) {
344+
bool cross(const plane &p1, const plane &p2, const plane &p3,
345+
PT &res) {
345346
double d = det(p1.n, p2.n, p3.n);
346347
if (sgn(d) == 0) {
347348
return false;

code/geometria/poligono2d.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ point centroide(const polygon &T) {
3434
return c;
3535
}
3636

37-
/* Retorna o perimetro do poligono T. (pode n funcionar como esperado se
38-
* o poligono for uma linha reta (caso degenerado))*/
37+
/* Retorna o perimetro do poligono T. (pode n funcionar como esperado
38+
* se o poligono for uma linha reta (caso degenerado))*/
3939
double poly_perimeter(polygon &T) {
4040
double perimeter = 0;
4141
int n = T.size();
@@ -177,4 +177,4 @@ polygon poly_intersect(polygon &P, polygon &Q) {
177177
if (R.size() > 1 && R.front() == R.back())
178178
R.pop_back();
179179
return R;
180-
}
180+
}

code/grafos/dinic.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ void init(int _nnode, int _src, int _snk) {
1919
}
2020

2121
void add(int a, int b, int c1, int c2) {
22-
to[nedge] = b, cap[nedge] = c1, flow[nedge] = 0, prox[nedge] = fin[a],
23-
fin[a] = nedge++;
24-
to[nedge] = a, cap[nedge] = c2, flow[nedge] = 0, prox[nedge] = fin[b],
25-
fin[b] = nedge++;
22+
to[nedge] = b, cap[nedge] = c1, flow[nedge] = 0,
23+
prox[nedge] = fin[a], fin[a] = nedge++;
24+
to[nedge] = a, cap[nedge] = c2, flow[nedge] = 0,
25+
prox[nedge] = fin[b], fin[b] = nedge++;
2626
}
2727

2828
bool bfs() {

code/grafos/mcmf_stefano.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ void BellmanFord(int s, int t) {
4141
for (int j = 0; j < E; ++j) {
4242
int u = to[j ^ 1], v = to[j];
4343

44-
if (cap[j] > 0 && dist[u] != inf && dist[u] + cost[j] < dist[v]) {
44+
if (cap[j] > 0 && dist[u] != inf &&
45+
dist[u] + cost[j] < dist[v]) {
4546
stop = false;
4647
dist[v] = dist[u] + cost[j];
4748
}

code/grafos/tarjan.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ void tarjanSCC(int u) {
1717
if (vis[v]) // condition for update
1818
dfs_low[u] = min(dfs_low[u], dfs_low[v]);
1919
}
20-
if (dfs_low[u] == dfs_num[u]) { // if this is a root (start) of an SCC
20+
if (dfs_low[u] ==
21+
dfs_num[u]) { // if this is a root (start) of an SCC
2122
while (true) {
2223
int v = S.back();
2324
S.pop_back();

code/matematica/fast-pow/testes/BIGMOD.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ using namespace std;
55
#define pb push_back
66
#define mp make_pair
77
#define debug(x) cout << __LINE__ << ": " << #x << " = " << x << endl;
8-
#define debug2(x, y) \
9-
cout << __LINE__ << ": " << #x << " = " << x << " " << #y << " = " \
8+
#define debug2(x, y) \
9+
cout << __LINE__ << ": " << #x << " = " << x << " " << #y << " = " \
1010
<< y << endl;
1111
#define all(c) (c).begin(), (c).end()
1212
#define F first
1313
#define S second
14-
#define UNIQUE(c) \
15-
sort(all(c)); \
14+
#define UNIQUE(c) \
15+
sort(all(c)); \
1616
(c).resize(unique(all(c)) - c.begin());
1717

1818
#define PI 3.1415926535897932384626433832795028841971

code/matematica/fast-pow/testes/MPOW.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ using namespace std;
55
#define pb push_back
66
#define mp make_pair
77
#define debug(x) cout << __LINE__ << ": " << #x << " = " << x << endl;
8-
#define debug2(x, y) \
9-
cout << __LINE__ << ": " << #x << " = " << x << " " << #y << " = " \
8+
#define debug2(x, y) \
9+
cout << __LINE__ << ": " << #x << " = " << x << " " << #y << " = " \
1010
<< y << endl;
1111
#define all(c) (c).begin(), (c).end()
1212
#define F first
1313
#define S second
14-
#define UNIQUE(c) \
15-
sort(all(c)); \
14+
#define UNIQUE(c) \
15+
sort(all(c)); \
1616
(c).resize(unique(all(c)) - c.begin());
1717

1818
#define PI 3.1415926535897932384626433832795028841971

code/pd/soma2D.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ long long sum(int x1, int y1, int x2, int y2) {
2626
if (y1 > 0)
2727
soma -= S[x2][y1 - 1];
2828
if (x1 > 0 && y1 > 0)
29-
soma += S[x1 - 1][x1 - 1];
29+
soma += S[x1 - 1][y1 - 1];
3030
return soma;
3131
}

code/string/aho_corasick.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ void aho() {
4444
continue;
4545
int v = T[u]; // No inicio v eh o maior prefixo e sufixo de u
4646
while (v && !sig[v][i])
47-
v = T[v]; // Testa para todo v se tambem pode ser
48-
// prefixo-sufixo de x
47+
v = T[v]; // Testa para todo v se tambem pode ser
48+
// prefixo-sufixo de x
4949
v = sig[v][i]; // Se dirige a posicao do maior prefixo-sufixo de x
50-
T[x] = v; // Salva que o maior prefixo-sufixo de x eh o no v
50+
T[x] = v; // Salva que o maior prefixo-sufixo de x eh o no v
5151
term[x] += term[v]; // Se v eh terminal e sufixo de x,
5252
q.push(x); // x tambem sera terminal
5353
}
@@ -57,4 +57,4 @@ void aho() {
5757
int init() {
5858
memset(sig, 0, sizeof sig);
5959
cnt = 1;
60-
}
60+
}

notebook.pdf

1.84 KB
Binary file not shown.

0 commit comments

Comments
 (0)