- 博客(16)
- 收藏
- 关注
原创 Semaphore 交替输出 ping pong
import java.util.concurrent.Semaphore; class Test extends Thread{ public static final int ITERATION = 10; public static Semaphore[] semas = new Semaphore[2]; private Semaphore[] m_semas = new Semap
2014-06-10 14:04:48
895
原创 python 2048 纯console
import random def printBoard(board,score): for line in board: #print " ".join(map(str,line)) def transform(x): if x == "0": return "_" else: return x print "%5s%5s%5s%5s" % tuple(
2014-05-18 11:35:22
4127
原创 c++ 函数对象动态规划解斐波那契数列
#include #include using namespace std; typedef long long int intLong; class Fib{ public: vector v; Fib() {v.push_back(0);v.push_back(1);} intLong operator() (intLong n) { if (v.size() >
2014-01-07 13:11:09
1125
原创 cpp study
#include #include #include #include #include #include #include using namespace std; class Point { private: int x,y; public: Point(int x,int y):x(x),y(y){} double slopeTo(const Point& th
2014-01-06 18:57:00
3486
原创 二分图
class Graph: def __init__(self,n): self.n = n self.v = [[] for i in range(n)] def addEdge(self,a,b): self.v[a].append(b) def edges(self,a): return self.v[a]
2013-11-03 17:01:45
561
原创 Dragon Maze,python
def readMap(): m,n = [int(i) for i in stdin.readline().strip().split()] #print >> stderr,n enx,eny,exx,exy = [int(i) for i in stdin.readline().strip().split()] matrix = [] for i in
2013-10-12 16:48:27
605
原创 sudoku
def readSudoku(): c = int(stdin.readline()) sudoku = [] for i in range(c**2): sudoku.append([int(j) for j in stdin.readline().strip().split()]) return sudoku,c def testLine(l
2013-10-12 10:18:10
588
原创 count inversion
def count(array): def merge(l,r): if len(l) == 0 or len(r) == 0: return (l+r,0) #print l,r n = 0 res = [] j,k = 0,0 lengthl = len(l)
2013-09-28 22:41:04
846
原创 kd树的java实现
public class KdTree { private int n; private Node root; private static final int LEFT = 1; private static final int RIGHT = 2; private static final int BOTTOM = 3; private static fin
2013-09-26 10:37:57
1823
1
原创 2013年google 在线笔试第五题被虐记。。
def memoize(f): def memf(*x): if x not in memf.cache: memf.cache[x] = f(*x) return memf.cache[x] memf.cache = {} return memf class Graph: def __init__(self,
2013-09-24 18:41:48
532
原创 heap sort java
public class Sort { private static void sink(int[] a,int k,int N) { while (2 * k <= N) { int j = 2 * k; if (j < N && less(a,j,j+1)) j++; if (!less(a,k,j)) break; exch(a,k,j); k
2013-09-15 20:12:04
853
原创 三路快排 duplicate keys
def exch(l,i,j): temp = l[i] l[i] = l[j] l[j] = temp def sort(l): quick(l,0,len(l) - 1) def quick(l,lo,hi): if lo >= hi: return v = l[0] i = lo gt = hi lt = lo
2013-09-14 16:06:31
519
原创 shell sort (python implementation)
def shellTest(l): h = 1 while h = 1: for i in range(h,len(l)): while i - h >= 0 and l[i] < l[i - h]: temp = l[i] l[i] = l[i - h] l[i - h] = temp i -= h h /= 3 return l
2013-09-09 08:53:39
490
原创 快排 c
int choosePivot(int a[],int len) { int temp; temp = a[len - 1]; a[len - 1] = a[0]; a[0] = temp; return 0; } void quickSort(int a[],int len) { int pivot = 0; int i = 1,j,temp; int flag =
2013-07-16 09:45:43
910
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅