Skip to content

Instantly share code, notes, and snippets.

View wdsrocha's full-sized avatar

Wesley Rocha wdsrocha

View GitHub Profile
@wdsrocha
wdsrocha / jogo_da_velha.py
Created June 2, 2017 17:21
Jogo da Velha simples (incompleto)
from random import randint
CPU_FACIL = "CPU (fácil)"
CPU_DIFICIL = "CPU (difícil)"
jogador = ["", ""]
simbolo = ["X", "O"]
def mostraTelaJogo(raw_tabuleiro):
print("-----------------")
print("{} vs {}".format(jogador[0], jogador[1]))
tabuleiro = [x if x else " " for x in raw_tabuleiro]
@wdsrocha
wdsrocha / p.cpp
Last active September 8, 2018 07:06
Speed comparison on using regex vs linear search to check if a string contains a digit.
#include <bits/stdc++.h>
using namespace std;
#define N 1000
bool hasDigitRegex(string& s) {
return regex_search(s, regex("[0-9]"));
}
bool hasDigitNormal(string& s) {
for (int i = 0; i < (int)s.size(); i++) {
@wdsrocha
wdsrocha / mo.cpp
Last active September 10, 2018 21:53
Mo's Algorithm
// http://codeforces.com/group/kZPk3ZTzR5/contest/101041/problem/D
// Nome do problema: Investigating the cartel
// Descrição: Quantos elementos com frequência maior que 1 no intervalo
// https://www.codepit.io/#/problems/5369c356f6fa9de49e5c7fa3/view
// Nome do problema: D-query
// Descrição: Quantos elementos diferentes no intervalo
// Resolve consultas em O((N+Q)*sqrt(N)+Q*log(Q))
#include <bits/stdc++.h>
@wdsrocha
wdsrocha / erdos_gallai.cpp
Created September 13, 2018 04:23
Erdős–Gallai theorem
// Erdős–Gallai theorem
// Gives a necessary and sufficient condition for a finite sequence
// of natural numbers to be the degree sequence of a simple graph.
// Must be sorted in non-increasing order.
// Popularidade no Facebook: https://www.urionlinejudge.com.br/judge/pt/problems/view/1462
#include<bits/stdc++.h>
using namespace std;
#define int long long
@wdsrocha
wdsrocha / URI_2024.cpp
Created September 15, 2018 03:39
Solução para o problema "2024 - Empilhando Presentes" do URI Online Judge
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);
#define endl '\n'
using namespace std;
#define inf ((int)1e9)
typedef pair <int, int> base;
@wdsrocha
wdsrocha / hld.cpp
Created September 28, 2018 12:09
Easiest HLD with subtree queries (incomplete)
// http://codeforces.com/blog/entry/53170
#include <bits/stdc++.h>
using namespace std;
#define N 100005
#define eb emplace_back
int n, u, v, q;
int sz[N], in[N], rin[N], out[N], chain[N], t;
vector <int> adj[N];
@wdsrocha
wdsrocha / plot_history_keras.py
Created December 22, 2018 09:14
Plot loss and accuracy from Keras model history.
# Extracted from https://www.kaggle.com/danbrice/keras-plot-history-full-report-and-grid-search
import matplotlib.pyplot as plt
def plot_history(history):
loss_list = [s for s in history.history.keys() if 'loss' in s and 'val' not in s]
val_loss_list = [s for s in history.history.keys() if 'loss' in s and 'val' in s]
acc_list = [s for s in history.history.keys() if 'acc' in s and 'val' not in s]
val_acc_list = [s for s in history.history.keys() if 'acc' in s and 'val' in s]
if len(loss_list) == 0:
print('Loss is missing in history')
@wdsrocha
wdsrocha / codeforces_template.cpp
Created March 3, 2019 07:19
Base code used on codeforces rounds
#include <bits/stdc++.h>
using namespace std;
#if DEBUG && !ONLINE_JUDGE
#define debug(args...) (Debugger()) , args
class Debugger {
public:
Debugger(const string sep = " | ") : first(1), sep(sep) {}
template <typename T> Debugger& operator , (const T& arg) {
if (first) first = false;
else cerr << sep;
@wdsrocha
wdsrocha / .vimrc
Last active July 8, 2019 14:17
My .vimrc for competitive programming
syntax on
set et ts=4 sw=4 sts=4 ai nu cindent
noremap <c-j> 15gj
noremap <c-k> 15gk
""forked" from https://github.com/naumazeredo/competitive-programming/blob/master/vimrc
@wdsrocha
wdsrocha / shutter_recount.md
Created April 9, 2019 14:45
Re-enumerate all elements in a folder (used for Shutter specifications)