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
//google的一道面试题,可以考虑用vector替换deque | |
#ifndef MIN_STACK_H | |
#define MIN_STACK_H | |
#include <vector> //for vector | |
#include <utility> //for pair | |
#include <functional> //for std::less<T> | |
#include <limits> | |
template<typename T, typename Comparator = std::less<T> > |
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 <sys/time.h> // for gettimeofday() | |
class StopWatch { | |
timeval started; | |
std::string msg; | |
public: | |
StopWatch(const std::string& m): msg(m) | |
{ gettimeofday(&started, NULL); } |
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
//shihongzhi -- 2012.3.9 | |
#include <stdio.h> | |
#include <string.h> | |
void KMP(char *T, char *P, int *pi) | |
{ | |
int tLen = strlen(T); | |
int pLen = strlen(P); | |
int k = 0; | |
for (int i=0; i<tLen; ++i) |
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://poj.org/problem?id=1458 | |
//http://poj.org/problem?id=1159 利用了滚动数组,要不然会内存溢出 | |
//http://poj.org/problem?id=2250 需要打印,用一个数组记录path状态 | |
//shihongzhi ---2012.3.8 | |
#include <stdio.h> | |
int dp[100][100]; | |
int LCS(char *a, char *b, int aLen, int bLen) | |
{ |
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://poj.org/problem?id=1050 | |
//http://poj.org/problem?id=2479 | |
//shihongzhi --2012.3.8 | |
#include <stdio.h> | |
int maxSubarray(int *A, int n) | |
{ | |
int max = 0; | |
int sum = 0; |
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.algorithmist.com/index.php/Longest_Increasing_Subsequence | |
//shihongzhi --2012.3.7 | |
#include <stdio.h> | |
int M[100]; //相应长度的最长子序列结尾值的下标,且此结尾值为最小值的情况 M[0]没有存东西,在这里没有意义 | |
int P[100]; //最长子序列的index索引 | |
//时间复杂度为O(nlogk) | |
int LIS(int *X, int n) |
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
/* 来至 Quake 3 的源码 */ | |
//求得的是 开平方的倒数,具体原理不懂 | |
float CarmSqrt(float x){ | |
union{ | |
int intPart; | |
float floatPart; | |
} convertor; | |
union{ | |
int intPart; | |
float floatPart; |
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://blog.codingnow.com/2006/02/double_to_int_magic_number.html | |
//http://www.cnblogs.com/Xiao_bird/archive/2010/03/26/1696908.html %f--8bytes %lf--8bytes %d--4bytes | |
#include <stdio.h> | |
union luai_Cast { double l_d; long l_l; }; | |
#define lua_number2int(i,d) { volatile union luai_Cast u; \ | |
u.l_d = (d) + 6755399441055744.0; (i) = u.l_l; } | |
int main() | |
{ |
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 <stdlib.h> | |
#define MAX 7 | |
int cake[MAX][MAX],diff[MAX][MAX-1]; | |
int min = 100000; | |
void compute(int m, int n, int r, int v) | |
{ |
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
import maya.cmds as cmds | |
f1 = open(r"C:\Users\shihongzhi\Desktop\newproject\test\sparse3dpoint-absolute.txt") | |
i = 0 | |
for line in f1.readlines()[40:]: | |
if i%6 == 0: | |
point = [float(t) for t in line[:-2].split(" ")] | |
#cmds.spaceLocator(p=(point[0],point[1],point[2])) | |
cmds.sphere(p=point,r=0.01) | |
elif i%6 == 1: |