ITeye博客

junfeng_feng的博客

junfeng_feng · 共 25 篇文章

2012书单===========一不小心2012马上就结束了

再总结反省一下,12年远没有11年那样看了很多书(只是看了,并不代表成长很多)。 总结一下11年记得最清的是学习了Python,比之前更熟悉C++,初步开始使用Linux,接触互联网广告。 先罗列一下12年看过的书吧: 1. 《Effective STL》 这个不用说了,想使用C++ STL都应该读一下,虽然我现在书中内容基本都忘记了,而且国内很难买到正版的书(我的就是复印的)。 2. 《深度探索C++对象模型》 通过本书可以了解编译器做了哪些事情,以及对象内存空间模型。了解C++倒底哪些是导致性能影响的,还有就是为什么要用C++。 3. 《重构》 一本好书,可是我自己的真正从0开始写一个程…

2012-12-01 23:39 · 评论(0)

ubuntu10.10升级gcc到4.7------以便支持C++11

先解释一下,为什么从09年开始就一直使用ubuntu10.10,大三的时候开始接触虚拟机VmWare使用Ubuntu。那时不懂什么是LTS,在这个虚拟机上安装了vim,g++,jdk,mysql,xlamp,python2.7,curl,go,adobe,ibus,chrome,firefox,qq,msn,openfetion,open office,msn等所以就不方便升级到12.04。 P.S.我不喜欢12.04的新风格。 进入正题 搜索“ubuntu 升级到gcc4.7” sudo add-apt-repository ppa:ubuntu-toolchain-r/test sudo…

2012-12-01 23:13 · 评论(0)

Deep Learning 自学

Deep Learning 介绍 Deep Learning is a new area of Machine Learning research, which has been introduced with the objective of moving Machine Learning closer to one of its original goals: Artificial Intelligence. Deep Learning 动机 Deep Learning --主要用于NLP(自然语言处理),可用于情感分析 -- 算法库 (Python) -- Deep Belief Ne…

2012-11-24 16:41 · 评论(0)

链表含有随机rand指针的复制

#include<iostream> #include<cstdio> #include<cstdlib> using namespace std; class Node { public: Node* next; Node* rand; int value; }; Node* copy_list_with_rand_ptr(Node* list) { if(list == NULL) { return NULL; } /* * 参考:http://hi.baidu.com/gkqofoydngbjqtq/item/6345d6104b7a8d06e65c36a3 * 1、复制链表中的每一个…

2012-11-24 16:23 · 评论(0)

统计1..n 中出现了多少个数字

如 1,2,3,...10出现11个数字,1,2,3..11出现了13个数字。 现在知道出现d个数字,求n,如果d非法,输出impossible。 算法的思想是:计算n = 9, 99, 999...这些长度为1,2,3...的各个数的出现的数字个数,反推d。 int calc_from_number_of_digits(int d) { if(d < 9) return d; int n = 0; int last_n = 0; int len = 1; while(d > n) { last_n = n; n += (pow(10, len) - (len > 1? pow(10, le…

2012-11-11 23:36 · 评论(0)

二分查找

二分查找查找key最左和最右的位置 利用这个特点,可以在O(log n)时间 在排序的数组中,统计一个数出现的次数。如[1,2,2,3],2出现了两次 //most_left_or_right: true 表示最左, false表示最右 int binary_search_most_left_or_right(int* array, int size, int key, bool most_left_or_right = true) { int low = 0; int high = size - 1; while(low <= high) { int mid = (low + high) …

2012-11-11 23:28 · 评论(0)

leetcode inteview code: Plus One

class Solution { public: vector<int> plusOne(vector<int> &digits) { // Start typing your C/C++ solution below // DO NOT write int main() function vector<int> result; int carray_bit = 0; digits[digits.size()-1] += 1; for(int i=digits.size()-1;i>=0;i--) { if(carray_bit) { result.push_back(1 + digits[…

2012-10-09 21:31 · 评论(0)

leetcode interview questions: Longest Common Prefix

//需要注意细节 class Solution { public: string longestCommonPrefix(vector<string> &strs) { // Start typing your C/C++ solution below // DO NOT write int main() function //sort(strs.begin(),strs.end()); string result(""); if (strs.size()==0) { return result; } int idx = 0; while(1) { for(int i=0;i<strs.si…

2012-10-09 21:20 · 评论(0)

leetcode interviw questions: Maximum Subarray

使用统计学的方法:O(n) 分治的方法,比较复杂 class Solution { public: int maxSubArray(int A[], int n) { // Start typing your C/C++ solution below // DO NOT write int main() function int maxendinghere=A[0]; int max = maxendinghere; for(int i=1;i<n;i++) { if (maxendinghere > 0) { maxendinghere = maxendinghere + A[i]; } …

2012-10-09 20:53 · 评论(0)

LeetCode interview Qustions: Anagrams

http://www.leetcode.com/onlinejudge class Solution { public: vector<string> anagrams(vector<string> &strs) { // Start typing your C/C++ solution below // DO NOT write int main() function multimap<string,string> map; for(int i=0;i<strs.size();i++) { if(strs[i].length()>0){ string value = strs[i]; so…

2012-10-09 17:12 · 评论(0)

LeetCode Interview Qustions: Add Two Number

直接使用加法 /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode *addTwoNumbers(ListNode *l1, ListNode *l2) { // Start typing your C/C++ solution below // DO NOT write int main() func…

2012-10-09 16:10 · 评论(0)

LeetCode interview Questions:Add binay

LeetCode interview Questions:Add binay 1.int之类的数可以使用small 2.直接在字符串使用二进制的加法 http://www.leetcode.com/onlinejudge 需要 class Solution { public: int string_to_int(string str) { int result = 0; int level = 1; for(int i = str.length() - 1; i >=0 ; i--) { if (str[i] == '1') { result += level; } level <<= 1;…

2012-10-09 15:52 · 评论(0)

C++ 可以声明非常量大小的数组

#include<iostream> using namespace std; int main() { uint32_t size; cin >> size; int arr[size]; printf("size address::%x\n", &size); printf("array address::%x\n", &arr[0]); return 0; } 这段代码,可以编译通过。可以在栈上开辟一个运行时才知道大小的数组。(参考:http://ericwang.github.com/c_cpp/2010/02/10/c_Variable_length_arrays.html) 可能…

2012-08-27 19:27 · 评论(0)

Information Gain 计算 python实现

from math import log def I(*args): total = sum(args) + 0.0 result = 0.0 for i in args: if i == 0: result += 0 else: result += i / total * log( i / total, 2) return -result #num表示分类的个数 def E(num, *args): if len(args) % num != 0: print "Error len(args)" result = 0.0 total = sum(args) for x in xrange(…

2012-06-10 16:06 · 评论(0)

Apri 算法 Python 实现

#!C:/Python27/python.exe #coding=gbk import sys __author__ = "junfeng_feng" """Python实现Apri算法 input:数据文件名 最小支持度 ouput:所有频繁项集 支持度 Usage:python Apri.py filename min_surpport Exampe: python Apri.py data.txt 2 3点说明 1、使用Python不到70行的代码,简洁完整的实现Apri算法 2、使用内存存放数据(Python会做相应大文件的优化) 3、代码易读,易理解 存在的问题: 1、超大的文件,…

2012-06-05 20:13 · 评论(0)