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
int find_kth(int *v, int n, int k) { | |
if (n == 1 && k == 0) return v[0]; | |
int m = (n + 4)/5; | |
int *medians = new int[m]; | |
for (int i=0; i<m; i++) { | |
if (5*i + 4 < n) { | |
int *w = v + 5*i; | |
for (int j0=0; j0<3; j0++) { | |
int jmin = j0; |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
from bisect import bisect_left, bisect_right | |
def solve(numbers, a, b): | |
answer = bisect_right(numbers, b) - bisect_left(numbers, a) | |
return answer if answer > 0 else 0 | |
def main(): | |
numbers = [1, 4, 9] | |
previous = ('012', ['']) |
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
def distance(points, i, j): | |
x1, y1 = points[i] | |
x2, y2 = points[j] | |
return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5 | |
def find_root(height_and_parent, i): | |
hi, pi = height_and_parent[i] | |
if pi is None: | |
return i | |
return find_root(height_and_parent, pi) |
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
def distance(points, i, j): | |
x1, y1 = points[i] | |
x2, y2 = points[j] | |
return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5 | |
def merge_root(root, i, j): | |
good, bad = sorted([root[i], root[j]]) | |
bad_keys = [k for k, v in root.iteritems() if v == bad] | |
for key in bad_keys: | |
root[key] = good |
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
""" | |
A short script that, given an artist, scrapes all his/her/their songs | |
from 'http://letras.terra.com.br' | |
Dependence: BeautifulSoup, to parse the lyrics from each song page. | |
Author: Andre Lima - http://github.com/andlima | |
Licensed under MIT License |
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
int quick_find_kth(int *v, int n, int k) { | |
if (n == 1 && k == 0) return v[0]; | |
int pivot = v[n-1]; | |
int store = 0; | |
for (int i=0; i<n-1; i++) { | |
if (v[i] < pivot) { | |
swap(v[i], v[store++]); | |
} |
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> | |
typedef unsigned long long int t_item; | |
static t_item all_true = ~0LL; | |
#define BITS sizeof(t_item) | |
void init_with_true(t_item *bitset, int maximum) { |
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> | |
typedef unsigned long long int t_item; | |
#define BITS sizeof(t_item) | |
void init(t_item *bitset, int maximum) { | |
int p = maximum / BITS; | |
int i; |
NewerOlder