Skip to content

Instantly share code, notes, and snippets.

package com.algorithims
import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;
public class BinarySearch {
Random random;
Scanner input;
int[] num;
@aajjbb
aajjbb / gemfile
Created April 29, 2011 02:01
gemfile
source 'http://rubygems.org'
gem 'rails', '3.0.7'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'mysql2'
# Use unicorn as the web server
@aajjbb
aajjbb / UnionFind.cpp
Created June 18, 2012 02:12
Cool UnionFind implementation
#include <iostream>
using namespace std;
struct UnionFind {
int N, *id, *sz;
UnionFind(int _N) {
N = _N;
id = new int[_N];
sz = new int[_N];
@aajjbb
aajjbb / MaximumFlow.cpp
Created August 10, 2012 16:54
Edmonds-Karp implementation
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <string.h>
#include <stdio.h>
#define MAXN 110
#define INF 1000000000;
@aajjbb
aajjbb / Segment.cpp
Created September 29, 2012 18:27
Segment Tree for Range Minimum Query
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <memory>
@aajjbb
aajjbb / DengklekTryingToSleep.java
Created November 22, 2012 01:07
TopCoder SRM 532 DIV 2 250 Solution
import java.util.*;
import java.math.*;
public class DengklekTryingToSleep {
public int minDucks(int[] ducks) {
Arrays.sort(ducks);
Set<Integer> aux = new HashSet<Integer>();
for(int i: ducks) aux.add(i);
@aajjbb
aajjbb / DengklekMakingChains.java
Created November 22, 2012 17:17
TopCoder SRM 532 DIV 2 600 Solution
import java.util.*;
import java.math.*;
public class DengklekMakingChains {
public int maxBeauty(String[] chains) {
int ans = 0, if_not_possible_ans = 0;
for(int i = 0; i < chains.length; i++) {
int tmp = 0;
for(int j = 0; j < 3; j++) if(chains[i].charAt(j) != '.') {
@aajjbb
aajjbb / TicTacToeTomek.cpp
Created April 14, 2013 00:32
Solution for problem A - Tic-Tac-Toe-Tomek from Google Code Jam 2013 - Qualification Round
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <memory>
@aajjbb
aajjbb / Lawnmower.cpp
Created April 14, 2013 00:47
Solution for problem: B - Lawnmower - Google Code Jam Qualification Round - 2013
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <memory>
@aajjbb
aajjbb / FairAndSquare.py
Created April 14, 2013 00:50
Solution for Problem: C - Fair and Square - Google Code Jam Qualification Round 2013
import sys
values = [1, 4, 9, 121, 484, 10201, 12321, 14641, 40804, 44944, 1002001, 1234321, 4008004, 100020001, 102030201,
104060401, 121242121, 123454321, 125686521, 400080004, 404090404, 10000200001, 10221412201, 12102420121,
12345654321, 40000800004, 1000002000001, 1002003002001, 1004006004001, 1020304030201, 1022325232201,
1024348434201, 1210024200121, 1212225222121, 1214428244121, 1232346432321, 1234567654321, 4000008000004,
4004009004004, 100000020000001, 100220141022001, 102012040210201, 102234363432201, 121000242000121,
121242363242121, 123212464212321, 123456787654321, 400000080000004, 10000000200000001, 10002000300020001,
10004000600040001, 10020210401202001, 10022212521222001, 10024214841242001, 10201020402010201,
10203040504030201, 10205060806050201, 10221432623412201, 10223454745432201, 12100002420000121,