Skip to content

Instantly share code, notes, and snippets.

View juanplopes's full-sized avatar
🌲
Is that a Segment Tree problem?

Juan Lopes juanplopes

🌲
Is that a Segment Tree problem?
View GitHub Profile
#include <iostream>
using namespace std;
int X[200];
int trucks(int P, int maximum) {
int count = 0, current = 0;
for(int i=0; i<P; i++) {
if (X[i] > maximum) return 10000000;
if (current + X[i] > maximum) {
import java.io.IOException;
import java.io.OutputStream;
public class LazyOutputStream<T extends OutputStream> extends OutputStream {
private final Factory<T> factory;
private T stream;
public LazyOutputStream(Factory<T> factory) {
this.factory = factory;
}
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <cmath>
#include <set>
using namespace std;
int T[][501] = {{0,1,1,2,2,2,3,3,3,3,4,4,4,4,4,5,5,5,5,5,5,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9,9,9,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,12,12,12,12,13,13,13,13,13,13,13,13,13,13,13,13,13,13,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,24,24,24,24,24,24,24,24,24,24,24,
@juanplopes
juanplopes / mvngithub.py
Last active May 19, 2018 12:34
Python 2 script that asks github for new application token and saves it on .m2/settings.xml
#!/usr/bin/env python
import httplib, getpass, base64, json, datetime, sys, socket, xml.etree.ElementTree as ET, os.path as path, os
NS = {'n':'http://maven.apache.org/SETTINGS/1.0.0'}
DEFAULT_REPO_KEY = 'your-repo-key'
def make_auth(username, password):
return base64.b64encode('{}:{}'.format(username, password))
def make_token(repokey, username, password, token2fa):
def cnt(v):
x, y, z, u, w = bool(v&1), bool(v&2), bool(v&4), bool(v&8), bool(v&16)
return ("T" if
(x or y or w) and (z or not w or v) and (not z or not w or not v) and
len(set([x, y, w])) == 2 and
len(set([z, not w, v])) == 2 and
len(set([not z, not w, not v])) == 2
else "F")
import sys
def kmp_init(P):
F = [0] * (len(P)+1)
i, j = 1, 0
while i<len(P):
if P[i] == P[j]:
i += 1; j += 1; F[i] = j
elif j == 0:
i += 1; F[i] = 0
def primes_up_to(N):
sieve = N*[True]
for i in range(2, N):
if not sieve[i]: continue
yield i
for j in range(i*i, N, i):
sieve[j] = False
def primeFactors(N):
answer = ''
@juanplopes
juanplopes / keybase.md
Created May 27, 2017 00:33
keybase.md

Keybase proof

I hereby claim:

  • I am juanplopes on github.
  • I am juanplopes (https://keybase.io/juanplopes) on keybase.
  • I have a public key ASAbnYPzQC3kur2g1skku3Eodfvw_egjtxXfetmlGRTC-wo

To claim this, I am signing this object:

@juanplopes
juanplopes / fighting_the_zombie.cpp
Created January 10, 2017 13:04
Hacker Cup 2017 solutions
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <iomanip>
using namespace std;
int DD[6] = {4, 6, 8, 10, 12, 20};
double D[6][25][500];
@juanplopes
juanplopes / generate.py
Created November 3, 2016 00:35
Generates ILP problem to be solved by glpsol
from collections import defaultdict
def name1(i):
return chr(ord('A')+i)
def name2(x, n):
return ''.join(name1(i) for i in xrange(n) if x&(1<<i))
def print_model(L, U, n, G):
for x in range(1, 2**n):