This file contains hidden or 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
#pragma once | |
#include <Windows.h> | |
#include <iostream> | |
// How to use: | |
// Example 1: | |
// double d1 = Tick(); | |
// double d2 = Tick(); | |
// double time = d2 - d1; | |
// |
This file contains hidden or 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
// http://www.oiers.cn/pack/Index.html#sec3 | |
// 0-1背包问题: | |
// 一个小偷带了一个背包去超市偷东西,超市有N件物品,每件物品的重量与价值分别为w[i]和v[i], | |
// 而小偷的背包最多只能装重量为M的东西 - 小偷该怎么选才能拿走价值最多的东西? | |
// 这是一个经典的动态规划算法: | |
// 状态:f(n, m),依次考虑每个物品,f为前n个物品,放入容量为m的背包的最大value, | |
// 但么不难看出,f(N,M)是我们要求的结果 | |
// |
This file contains hidden or 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> | |
// A homemade memcpy function. | |
// 1. Handle the memory overlap | |
// 2. Copy 4 bytes a time first as int, then copy the left ones as char (at most 3) | |
void* mymemcpy(void* dest, const void* src, size_t count) | |
{ | |
if(NULL == dest || NULL == src || dest == src) | |
return dest; |
This file contains hidden or 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 <stack> | |
#include <iostream> | |
#include <cassert> | |
#include <LazyTest.h> // my unittest framework | |
// use 2 stacks to implement a queue - first in first out | |
// push - pop - front - back - size - empty | |
// Imagine that 2 stack bend as a "U" shape, with each top as back and front | |
template <class T> | |
class queue |
This file contains hidden or 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 <iostream> | |
#include <functional> | |
#include <iterator> | |
#include "../LazyLib/stdext.h" | |
using namespace std; | |
int partition1(int* a, int i1, int i2) | |
{ | |
int x = a[i2]; |
This file contains hidden or 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 <algorithm> | |
#include <ctime> | |
#include <vector> | |
#include <iostream> | |
using namespace std; | |
// Binary search for a given value in a vector, and return the index of the first found value (-1 for not found). | |
// The vector should be sorted in ascending order | |
// Notice: | |
// 1. Use unsigned int for index type |
This file contains hidden or 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 <cassert> | |
// This class manages available ID use a single linked list, which is implemnent by an array | |
// We simply use an integer array to save half space as we could resue the "value" feild & the "next" feild: | |
// 1. The value type is of the same type of index | |
// 2. The value's range is the same as index | |
// | |
const static char LIST_END = -1; |
This file contains hidden or 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 main() { | |
00B61400 push ebp | |
00B61401 mov ebp,esp | |
00B61403 sub esp,0C0h // esp指向栈顶 | |
00B61409 push ebx | |
00B6140A push esi | |
00B6140B push edi | |
00B6140C lea edi,[ebp-0C0h] | |
00B61412 mov ecx,30h //C0h 除以4,就是30h,因为rep stos用的是dword | |
00B61417 mov eax,0CCCCCCCCh //设置返回值为默认值:无效 |
This file contains hidden or 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 <iostream> | |
#include <algorithm> | |
#include <vector> | |
#include <iterator> | |
using namespace std; | |
bool compare(int a, int b) | |
{ |
This file contains hidden or 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
object factorialTest extends App | |
{ | |
def factorial(n: Int): Int = | |
{ | |
if(n == 0) 1 else n * factorial(n-1) | |
} | |
println(factorial(3)) | |
println(factorial(10)) |