Skip to content

Instantly share code, notes, and snippets.

#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#ifndef SEED
#define SEED 1
#endif
// Compile-time if then else
template<bool B, class T, class F>
struct ifthenelse { typedef T type; };
@ealmansi
ealmansi / interval products
Created June 14, 2014 18:33
icpc regional 2012 latin american: interval products
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long int lli;
#define MAXN 100005
lli N, K;
lli x[MAXN + 1];
@ealmansi
ealmansi / RRSCHED.cpp
Created June 18, 2014 23:12
SPOJ Problem Set (classical) 2826. Round-Robin Scheduling Problem code: RRSCHED
#include <iostream>
#include <utility>
#include <algorithm>
using namespace std;
#define mp make_pair
typedef long long int lli;
@ealmansi
ealmansi / gist:e9da8a9c4d8018c20920
Created June 26, 2014 03:35
2014 ACM-ICPC World Finals Problem D Game Strategy
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define MAX_N 30
#define MAX_OPTS 1000005
@ealmansi
ealmansi / gist:35e3763d9bde2f056baa
Created August 1, 2014 00:24
Problem: Petya and Inequiations
/*
7303013 2014-08-01 04:22:45 apaapa 111A - Petya and Inequiations GNU C++ Accepted 374 ms 0 KB
*/
#include <iostream>
using namespace std;
#define forr(i, d, h) for (int i = (d); i < (h); ++i)
unsigned long long int N, X, Y;
@ealmansi
ealmansi / gist:e18796c3dfd0481b47a9
Created August 1, 2014 00:54
Codeforces: 45D - Event Dates
/*
7303089 2014-08-01 04:51:42 apaapa 45D - Event Dates GNU C++ Accepted 30 ms 0 KB
*/
#include <iostream>
#include <algorithm>
using namespace std;
#define forr(i,d,h) for (int i = (d); i < (h); ++i)
#define repeat(n) forr(___, 0, n)
@ealmansi
ealmansi / cuenta.py
Last active August 29, 2015 14:05
ejercicio plp
def cuenta(nums):
return reduce(lambda r, x : (x + 4 + r) if (x + 4 > 5) else (r), nums, 0)
if __name__ == '__main__':
print [1,2,3], "->", cuenta([1,2,3])
@ealmansi
ealmansi / txt2num.py
Last active August 29, 2015 14:06
Spanish cardinal number to integer conversion
# -*- coding: utf-8 -*-
import re;
class Tokenizer:
def __init__(self, inp):
self.tokens = inp.lower().encode('utf8')
self.substitutions = [
("á", "a"), ("é", "e"), ("í", "i"), ("ó", "o"), ("ú", "u"), ("[^\w]", " "),
("(^| )un( |$)", " uno "), ("(^| )veintiun( |$)", " veintiuno "), ("(^| )cien( |$)", " ciento "), ("(^| )millon( |$)", " millones "), ("(^| )y( |$)", " "),
("(^| )once( |$)", " diez uno "), ("(^| )doce( |$)", " diez dos "), ("(^| )trece( |$)", " diez tres "), ("(^| )catorce( |$)", " diez cuatro "),
@ealmansi
ealmansi / teg.py
Last active December 28, 2017 01:07
TEG: probabilidad de conquistar otro país mediante ataques reiterados
#!/usr/bin/env python3
import math;
##########################################################################################
# Basado en: http://openpool.com.ar/reglamento/T.E.G.-REGLAMENTO.pdf
#
# Probabilidad de conquistar otro pais si atacamos sin frenar hasta que:
# i) conquistamos el otro pais, o
# ii) nos quedamos con una sola ficha y no podemos atacar más
@ealmansi
ealmansi / word-scrambler.py
Created September 17, 2014 19:08
Word scrambler (so called "Cambridge Effect")
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import re
import random
def myshuffle(xs):
for i in range(len(xs)):
ind = random.randint(i, len(xs) - 1)
xs[i], xs[ind] = xs[ind], xs[i]