This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public class MultisetPermutations { | |
private MultisetPermutations() { | |
} | |
public static void main(String[] args) { | |
for (List<Integer> li : permutate(Arrays.asList(1, 1, 2, 2))) { | |
System.out.println(li); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
def toGrey(num): | |
return (num >> 1) ^ num | |
def generate(n): | |
for i in xrange(2**n): | |
yield toGrey(i) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BinarySearch { | |
private BinarySearch() { | |
} | |
public static void main(String[] args) { | |
Integer[] data = {1,2,3,4,5,6,7,8,9}; | |
for (int i=0; i<=10; ++i) { | |
System.out.println(String.format("%d: %d", i, binarySearch(data, i))); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <assert.h> | |
#include <stdlib.h> | |
#define MAX(A, B) ((A)>(B)?(A):(B)) | |
static void print_paren(int n); | |
static void do_print(int n, int* idx, int k); | |
static void print_result(int n, int* idx); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include<stdlib.h> | |
#include<assert.h> | |
static void swap(int* data, int c) { | |
for (int i=0; c > 0; i+=2, --c) { | |
int tmp = data[i]; | |
data[i] = data[i+1]; | |
data[i+1] = tmp; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public class LowerBound { | |
private LowerBound() {} | |
final static class Node { | |
Node left, right; | |
final int val; | |
public Node(int val) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final class Zigzag { | |
private Zigzag() {} | |
/** | |
* given an array of integer, returns the maximun length of zig-zag | |
* subsequence | |
*/ | |
public static int zigzagSequence(int[] arr) { | |
if (arr.length < 2) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include<stdlib.h> | |
#include<assert.h> | |
#include<stdbool.h> | |
#define DUP (-1) | |
#define INVALID (-2) | |
static int comp(int a, int b, int c, int d) { | |
if (a == c) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
/** | |
* SRM 181 Div 1 - 3rd | |
*/ | |
public class KiloManX { | |
public static int leastShots(String[] damageChart, int[] bossHealth) { | |
final int size = bossHealth.length; | |
final int rows = 1 << size; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public final class Escape { | |
private static final int size = 501; | |
private static final int NotSeen = -1; | |
private enum Type { | |
Normal, Harmful, Deadly | |
} |