- 博客(29)
- 收藏
- 关注
原创 二叉树ADT,周游二叉树,递归非递归,求节点的父节点,兄弟节点
#pragma once#include "BinaryTreeNode.h"#includeenum Tags{Left,Right};templateclass StackElem{public: BinaryTreeNode* pointer; Tags tag;};template class BinaryTree{public: BinaryTree(){
2014-07-22 20:43:06
723
原创 KMP算法
#include#includeusing namespace std;int *nextfun(string P){ int m = P.length(); int *ret = new int[m]; ret[0] = 0; for(int i = 1 ; i < m ; i++){ int k = ret[i-1]; if(P[i] == P[k]){ ret[i
2014-07-22 14:51:12
516
原创 LeetCode Reverse Polish Notation求逆波兰表达式值
public class Solution {public static int evalRPN(String[] tokens) { Stack stack = new Stack(); String operatorsString = "+-*/"; for(int i = 0 ; i < tokens.length ; i++) { if(!operatorsStr
2014-04-15 14:18:09
557
原创 LeetCode Two Sum
Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the target, whe
2014-04-15 10:59:00
514
原创 几种排序算法的代码
#include using namespace std;//insert sortvoid insertSort(int a[],int size){ int tmp; int i,j; for(i = 1 ; i < size ; i++) { tmp = a[i]; for(j = i - 1 ; j >=0 ; j--) { if(a[j] > tmp)
2014-04-10 10:39:06
572
原创 二叉查找树C++
#pragma once#include using namespace std;enum ORDER_MODE{ORDER_MODE_PREV = 0,ORDER_MODE_MID,ORDER_MODE_POST};template struct BinaryNode{T element;BinaryNode *left;
2014-04-08 11:51:08
513
原创 二叉树的创建和遍历C++实现
#ifndef _BiTree#define _BiTree#include #include #include using namespace std;struct BiNode{ char data; struct BiNode *left,*right;};class BiTree{public: BiTree(); ~BiTree(); BiNode *g
2014-04-07 13:41:34
888
原创 SimpleTag_TFIDF++
'''Created on 2014-03-05@Author:Dior'''import randomimport mathimport operatorclass SimpleTagBased(): #The constructor function def __init__(self,filename): self.filename=
2014-03-09 19:07:45
788
1
原创 SimpleTag_TFIDF
'''Created on 2014-03-05@Author:Dior'''import randomimport mathimport operatorclass SimpleTagBased(): #The constructor function def __init__(self,filename): self.filename=
2014-03-09 19:05:56
748
原创 SimpleTagBased
'''Created on 2014-03-05@Author:Dior'''import randomimport mathimport operatorclass SimpleTagBased(): #The constructor function def __init__(self,filename): self.filename=
2014-03-09 19:04:50
1258
原创 在MovieLens数据集上用SVD进行评分预测
参考了Yehuda Koren 08年的论文Factorization Meets the Neighborhood: a Multifaceted Collaborative Filtering Model代码如下:'''Version:1.0Created on 2014-02-25@Author:Dior'''import randomimport mathimpor
2014-02-25 19:47:27
8464
1
原创 python列出目录下所有的文件
import osdef listAllFilesAndDirs(level,path): files = os.listdir(path) for file in files: print "--"*(level+1)+file if os.path.isdir(file): listAllFilesAndDirs(le
2013-12-31 13:17:12
997
转载 void和void指针
void在英文中作为名词的解释为“空虚;空间;空隙”;而在C语言中,void为“无类型”,相应的void *为“无类型指针”。void似乎只有“注释”和限制程序的作用,当然,这里的“注释”不是为我们人提供注释,而是为编译器提供一种所谓的注释。void的作用: 1.对函数返回的限定,这种情况我们比较常见。 2.对函数参数的限定,这种情况也是比较常见的。
2013-11-23 22:01:16
519
原创 函数指针和指针函数的区别
【函数指针】 在程序运行中,函数代码是程序的算法指令部分,它们和数组一样也占用存储空间,都有相应的地址。可以使用指针变量指向数组的首地址,也可以使用指针变量指向函数代码的首地址,指向函数代码首地址的指针变量称为函数指针。1.函数指针定义函数类型 (*指针变量名)(形参列表);“函数类型”说明函数的返回类型,由于“()”的优先级高于“*”,所以指针变量名外
2013-11-23 21:39:59
590
原创 HD1008简单题
#include #include using namespace std;int main(){ //ifstream cin("input.txt"); int floor[100],visit[100]; memset(visit,0,sizeof(visit)); int stop=5,upSpeed=6,downSpeed=4,n=0,pre,time; while (
2013-11-23 15:51:06
649
原创 HD1009 经典贪心
#include #include #include #include using namespace std;#define MAX 1000struct room{ int f,j; double rate; bool operator<(room r) { return rate>r.rate; }};room rooms[MAX];int main(){
2013-11-23 15:22:31
716
原创 HDOJ 1010 深度优先搜索 用例过了还是WA了不知道为什么
没有用剪枝,就是纯粹的dfs,不知道为什么WA了。洗洗睡了。#include #include using namespace std;#define MAX 8char map[MAX][MAX];int n,m,t;int dx,dy;int d[4][2] = {{0,1},{-1,0},{0,-1},{1,0}};bool flag=false;void dfs(int
2013-11-16 00:03:26
588
转载 母函数与排列组合
母函数与排列组合 在谈论母函数问题之前,我们先看一个简单的问题描述:假如有两组数据(A,B)和(C,D),每组中选出一个构成一个组合,总共有几种选法?很显然总共有4种选法:AC,AD,BC,BD。而且很容易联想到这个式子(A+B)*(C+D)=A*C+A*D+B*C+B*D。式子中的几个乘积项就是上面的4种选法。假如把问题换一下:每组中选出一个或0个数据构成组合,总共有几种组合?那么结果
2013-11-12 22:16:10
831
原创 HDOJ 2059 龟兔赛跑
Problem Description据说在很久很久以前,可怜的兔子经历了人生中最大的打击——赛跑输给乌龟后,心中郁闷,发誓要报仇雪恨,于是躲进了杭州下沙某农业园卧薪尝胆潜心修炼,终于练成了绝技,能够毫不休息得以恒定的速度(VR m/s)一直跑。兔子一直想找机会好好得教训一下乌龟,以雪前耻。最近正值HDU举办50周年校庆,社会各大名流齐聚下沙,兔子也趁此机会向乌龟发起挑战。虽然乌龟深知
2013-11-10 10:16:17
672
原创 HD 1058 Humber Numbers。本地都通过了最终还是WA了,莫名其妙
#include #include using namespace std;int findMin(int a,int b){ return a>=b?b:a;}int main(){ //ifstream cin("input.txt"); int dp[5844],n=1; dp[1] = 1; int a=1,b=1,c=1,d=1; for (int i = 2
2013-11-10 00:06:26
747
原创 HDOJ 2084 数塔问题
自底向上求解。状态转移方程是dp[i][j] = max(dp[i+1][j],dp[i+1][j+1]) + a[i][j].一开始一直WA,后来把数组最大下标值从100改成101就AC了。#include #include using namespace std;int findMax(int a , int b){ return a >= b ?a:b;}int m
2013-11-09 23:02:52
759
原创 HDOJ 1159 Common Subsequence
其实就是最长公共子序列的简化版。#includeint c[1000][1000];int max(int x,int y){ if(x<y) x=y; return x;}int main(){ char a[1000],b[1000]; int i,j; while(scanf("%s%s",a,b)!=-1){ for(i=0;i<=1000;i++){
2013-11-09 10:33:21
606
原创 HDOJ 1087 Super Jumping! Jumping! Jumping!简单DP
题目是:Problem DescriptionNowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very popular in HDU. Maybe you are a good boy, and know little about this game, so I introduce it to
2013-11-09 01:52:20
445
原创 HDOJ1160 FatMouse's Speed 弄了一晚上还是WA了,感觉有不止一个解啊
#include #include #include #include using namespace std;struct FatMouse{ int id; int next; int weight; int speed; FatMouse(int w,int s) { weight = w; speed = s; } bool operator<(FatM
2013-11-07 22:37:50
753
1
原创 求最长递减子序列
#include #include #include using namespace std;int main(){ifstream cin("input.txt");int n;int a[100],dp[100],max=0,index;cin>>n;for (int i = 0 ; i {cin>>a[i];}for (int i =
2013-11-07 21:52:42
711
原创 HDOJ1052田忌赛马
Here is a famous story in Chinese history."That was about 2300 years ago. General Tian Ji was a high official in the country Qi. He likes to play horse racing with the king and others.""Both o
2013-11-07 20:17:33
941
原创 HDOJ1004 so easy
#include #includeusing namespace std; #define Min -999999 int main() { //ifstream cin("input.txt");int data[100000],start,end; int m; int step=1; cin>>m
2013-11-07 20:16:42
640
原创 HDOJ1003 简单DP问题
#include #includeusing namespace std; #define Min -999999 int main() { //ifstream cin("input.txt");int data[100000],start,end; int m; int step=1; cin>>m
2013-11-07 20:16:10
590
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人