This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<bits/stdc++.h> | |
using namespace std; | |
int main(){ | |
int a, b, c; | |
cin >> a >> b >> c; | |
if(a == b) cout << c << "\n"; | |
else if(a == c) cout << b << "\n"; | |
else cout << a << "\n"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<bits/stdc++.h> | |
using namespace std; | |
vector <int> adj[128]; | |
int colour[128], mark[128], t; | |
bool dfs(int u, int v, int c){ | |
bool paint = 0; | |
mark[u] = t; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<bits/stdc++.h> | |
using namespace std; | |
int mat[128][128]; | |
int main(){ | |
int n; | |
cin >> n; | |
for(int i = 1; i <= n; ++i) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
int v[1024]; | |
int main(){ | |
int n; | |
cin >> n; | |
for(int i = 1; i <= n; ++i){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
set <int> tree; | |
vector <int> adj[123466], level[123466]; | |
int p[123466], dist[123466], ana[123466], imp[123466]; | |
void dfs_enum(int u){ | |
int v; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
#define ff first | |
#define ss second | |
using namespace std; | |
typedef pair<int, int> pii; | |
vector <int> sites; | |
vector <pii> adj[20010]; | |
int dist[32][20010], dp[2][20][1 << 20], n, p, t; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Checar a posição lexicogŕafica de uma ordem de um vetor, O(n * n!) | |
int n, v[10], u[10], ans, stop; | |
cin >> n; | |
for(int i = 0; i < n; ++i){ | |
cin >> v[i]; //leitura, O(n) | |
} | |
for(int i = 0; i < n; ++i){ | |
u[i] = v[i]; //copio o vetor para outro, O(n) | |
} | |
sort(u, u + n) //ordenação, O(nlog(n)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Soma de conjunto, O(n*2^n) | |
int n, v[20], m; | |
cin >> n >> m; | |
for(int i = 0; i < n; ++i){ | |
cin >> v[i]; //leitura, O(n) | |
} | |
for(int mask = 0; mask < (1 << n); ++mask){ //passa por todos os subconjuntos O(2^n) | |
int soma = 0; | |
for(int i = 0; i < n; ++i){ //loop O(n) | |
if((1 << i)&mask){ //checa se um elemento está nesse subconjunto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Soma de conjunto | |
int n, v[20], m; | |
cin >> n >> m; | |
for(int i = 0; i < n; ++i) cin >> v[i]; //leitura, O(n) | |
for(int mask = 0; mask < (1 << n); ++mask){ //passa por todos os subconjuntos | |
int soma = 0; | |
for(int i = 0; i < n; ++i) | |
if((1 << i)&mask) //checa se um elemento esta nesse subconjunto | |
soma += v[i]; | |
if(m == soma){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//ordenação usando a STL | |
int n, v[100000]; | |
cin >> n; | |
for(int i = 0; i < n; ++i){ | |
cin >> v[i]; //custa O(n) | |
} | |
sort(v, v + n); //ordena o vetor, custa O(nlog(n)) | |
//n + nlog(n) = O(nlog(n)) |
NewerOlder