Skip to content

Instantly share code, notes, and snippets.

View mejibyte's full-sized avatar

Andrés Mejía mejibyte

View GitHub Profile
@mejibyte
mejibyte / gist:1268157
Created October 6, 2011 18:15
Implementation of Ukkonen's algorithm to build a prefix tree in O(n)
using namespace std;
#include <algorithm>
#include <iostream>
#include <iterator>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
@mejibyte
mejibyte / gist:1268709
Created October 6, 2011 21:20
Implementation of the Knuth-Morris-Pratt algorithm in C++
// http://www.spoj.pl/problems/NHAY/
#include <vector>
#include <iostream>
#include <string>
#include <cstdio>
using namespace std;
void kmp(const string &needle, const string &haystack) {
int m = needle.size();
vector<int> border(m + 1);
@mejibyte
mejibyte / gist:1268711
Created October 6, 2011 21:21
My implementation of the Knuth-Morris-Pratt algorithm in C++
// http://www.spoj.pl/problems/NHAY/
#include <vector>
#include <iostream>
#include <string>
#include <cstdio>
using namespace std;
void kmp(const string &needle, const string &haystack) {
int m = needle.size();
vector<int> border(m + 1);
@mejibyte
mejibyte / gist:1276400
Created October 10, 2011 20:20
12316 - Sewing Buttons with Grandma
import java.io.*;
import java.util.*;
import java.math.*;
public class Main {
public static void main(String[] args) throws FileNotFoundException {
Scanner cin = new Scanner(System.in);
//Scanner cin = new Scanner(new FileInputStream(new File("in.txt")));
int m, k;
@mejibyte
mejibyte / gist:1278464
Created October 11, 2011 15:45
11848 - Cargo Trains
// Accepted
using namespace std;
#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
@mejibyte
mejibyte / in.txt
Created October 17, 2011 16:23
Test cases for 12322 - Handgun Shooting Sport
10
-309 98 -258 204
-303 83 -251 98
-218 111 -287 31
-145 204 -23 257
-129 272 59 272
-8 159 74 130
150 146 68 174
59 196 128 242
@mejibyte
mejibyte / gist:1302544
Created October 20, 2011 22:10
12323 - Inspecting Radars
#include <iostream>
using namespace std;
const int MAXA = 360 * 2;
const int MAXH = 105;
int mat[MAXH][MAXA];
int a[MAXA];
int maximo_subarreglo(int ancho) {
@mejibyte
mejibyte / BusinessCenter.cpp
Created October 22, 2011 22:48
Solutions from little programming contest at UPB, October 22nd.
using namespace std;
#include<iostream>
#include<algorithm>
#include<iterator>
#include<sstream>
#include<fstream>
#include<cassert>
#include<climits>
#include<cstdlib>
#include<cstring>
@mejibyte
mejibyte / pi2.md
Created October 24, 2011 22:49 — forked from acadavid/pi2.md
Proyecto Integrador 2

Almacenamiento de la información.

Las necesidades de nuestro módulo en términos de almacenamiento y consulta son diferentes a las de los demás módulos. La diferencia principal es el volumen de datos a almacenar y la concurrencia de las consultas. En primer lugar, nuestro módulo almacenará muchísimos más datos que los demás; sólo el hecho de publicar un contenido, loggearse ó visitar un perfil almacenará una actividad en nuestro módulo.

Por las razones anteriormente expuestas, nuestra aplicación necesita un mecanismo altamente escalable. Este es el fuerte de las bases de datos NOSQL. Además, los queries tienen que tener tiempos rápidos de respuesta. Por estas razones creemos conveniente utilizar el motor MongoDB que ofrece estas ventajas (frente a otras desventajas como la imposibilidad de hacer consultas sobre atributos anidados de una entidad, aunque en nuestro caso esto no es necesario).

Las respuestas de nuestro servicio web estarán en formato XML. Sin embargo, en nuest

@mejibyte
mejibyte / gist:1332402
Created November 2, 2011 00:36
Skeleton for problem 579 from UVa
import java.util.*;
import java.io.*;
class Main {
public static void main(String [] args) throws IOException {
BufferedReader cin = new BufferedReader(new InputStreamReader(System.in));
PrintStream cout = System.out;
while (true) {
String s = cin.readLine();