On Pi

摘要: π計算Pi的公式计算Pi的C程序:int a=10000,b,c=2800,d,e,f[2801],g; main() {for(;b-c;) f[b++]=a/5;for(;d=0,g=c*2;c -=14,printf("%.4d",e+d/a),e=d%a) for(b=c; d... 阅读全文
posted @ 2014-06-08 15:48 mhgu 阅读(165) 评论(0) 推荐(0) 编辑

香港小學一年級入學考試題

摘要: 據說小学生几秒就做出;高中生几分钟;大学生半小时以上;博士可能要一辈子......What takes an elementary school student just seconds to do; takes a high school student several minutes; take... 阅读全文
posted @ 2014-06-08 11:29 mhgu 阅读(577) 评论(0) 推荐(0) 编辑

100steps

摘要: /* * remember the 100-steps ladder at the university of my graduation. * it's an unforgotable place. * these steps in hurry to another classroom, * sometimes one by one step, sometimes three into two steps and even one step. * nerver thoungh of the process thought the ladder. How may ways to pas 阅读全文
posted @ 2013-11-26 00:04 mhgu 阅读(251) 评论(0) 推荐(0) 编辑

酥醪羅浮山行游

摘要: 酥醪羅浮山行游Nov-09-2013延綿山黛清氣晰,翠染層林映日暉。路轉峰回雲不住,溪潺鳥鳴香暗飄。欲將凡塵身后灑,歡聲笑語諍不休。三三兩兩獨自行,孤孤單單秋色心。不畏前途迷無路,留得新標后來人。 阅读全文
posted @ 2013-11-15 23:57 mhgu 阅读(121) 评论(0) 推荐(0) 编辑

为什么不能够 向接受 const char ** 参数的函数,传入 char ** 参数?

摘要: /*为什么不能够 向接受 const char ** 参数的函数,传入 char ** 参数?网上找来的解答是:可以向接受 const T 的指针的地方传入 T 的指针(任何类型 T 都适用)。但是, 这个允许在带修饰的指针类型上轻微不匹配的规则(明显的例外) 却不能递归应用, 而只能用于最上层。我自己这样理解:(没有研究过编译器,就是瞎猜的。)1.const char** ccp_ptr; typedef const char * CCP; CCP * CCP_ptr;2.char** cp_ptr; typedef char* CP; CP * CP_ptr;3.const CP * c. 阅读全文
posted @ 2013-11-06 20:52 mhgu 阅读(541) 评论(0) 推荐(0) 编辑

linux shell 中 " if [ ]; ... then ... fi " 的使用

摘要: http://blog.chinaunix.net/uid-79084-id-97212.html [ -a FILE ] 如果 FILE 存在则为真。[ -b FILE ] 如果 FILE 存在且是一个块特殊文件则为真。[ -c FILE ] 如果 FILE 存在且是一个字特殊文件则为真。[ -d FILE ] 如果 FILE 存在且是一个目录则为真。[ -e FILE ] 如果 FILE 存在则为真。[ -f FILE ] 如果 FILE 存在且是一个普通文件则为真。[ -g FILE ] 如果 FILE 存在且已经设置了SGID则为真。[ -h FILE ] 如果 FILE 存在且是一个 阅读全文
posted @ 2013-11-06 19:33 mhgu 阅读(2403) 评论(0) 推荐(0) 编辑

使用“數制”解組合策略問題

摘要: 問題:序列123...N,N介于3和9之间,在其中加入+、-或者空格,使其和为0。如123456,1-2 3-4 5+6 7,等价于1-23-45+67=0。解答:網上找來的代碼。 1 //序列123...N,N介于3和9之间,在其中加入+、-或者空格,使其和为0, 2 //如123456 1-2 3-4 5+6 7 等价于1-23-45+67=0。请问,如何获得所有组合?使用递归和非递归。 3 //非递归算法 4 #include 5 #include 6 using namespace std; 7 8 void func (char* str); 9 void calc (cha... 阅读全文
posted @ 2013-09-29 23:24 mhgu 阅读(292) 评论(0) 推荐(0) 编辑

Wi-Fi Protected Access (WPA) Supplicant

摘要: WPA implements a new key handshake (4-Way Handshake and Group Key Handshake) for generating and exchanging data encryption keys between the Authenticator and Supplicant. This handshake is also used to verify that both Authenticator and Supplicant know the master session key. These handshakes are ide 阅读全文
posted @ 2013-09-27 12:06 mhgu 阅读(218) 评论(0) 推荐(0) 编辑

Open Computers and Software Inventory

摘要: OCS Inventory-NG(Open Computer and Software Inventory Next Generation)是一款开源的用于帮助网络或系统管理员来跟踪网络中计算机配置与软件安装情况的应用程序。相關資料:http://www.ocsinventory-ng.org/en/http://en.wikipedia.org/wiki/OCS_Inventoryhttp://viong.blog.51cto.com/844766/503463/http://linux.chinaunix.net/techdoc/system/2008/11/28/1048784.shtm 阅读全文
posted @ 2013-09-27 11:55 mhgu 阅读(359) 评论(0) 推荐(0) 编辑

touch screen -- tslib

摘要: tslib github:https://github.com/kergoth/tslib/tree/master/pluginstslib分析:http://www.cnblogs.com/leaven/archive/2010/06/09/1754905.htmltouch screen 的校正原理:http://blog.sina.com.cn/s/blog_5d9051c00100ee6w.htmlhttp://blog.sina.com.cn/s/blog_5d9051c00100eec9.html其他ts校正資料:http://download.csdn.net/detail/de 阅读全文
posted @ 2013-09-26 17:13 mhgu 阅读(223) 评论(0) 推荐(0) 编辑

static data

摘要: 對編譯單元内的static全局數據,如果這些數據沒有被使用,g++編譯器會自動remove掉這些數據,vc++好像沒有這麽"智能"。 阅读全文
posted @ 2013-09-25 17:15 mhgu 阅读(150) 评论(0) 推荐(0) 编辑

puzzle of managers and engineers

摘要: The FBI has surrounded the headquarters of the Norne corporation. There are n people in the building. Each person is either an engineer or a manager. All computer files have been deleted, and all documents have been shredded by the managers. The problem confronting the FBI interrogation team is to s 阅读全文
posted @ 2013-03-28 23:20 mhgu 阅读(160) 评论(0) 推荐(0) 编辑

c/c++ 的 main 前 main 後.

摘要: c/c++ 在 main 函數之前和之後發生的那些事。#include <stdio.h>#include <stdlib.h>#include <iostream>void foo(){ printf("call back atexit, C can do it after main.\n");}int bar(){ printf("global variable initialized, C can do it before main.\n"); atexit(foo); return 0;}int x = bar 阅读全文
posted @ 2013-03-04 21:50 mhgu 阅读(181) 评论(0) 推荐(0) 编辑

a linear-time algorithm for longest palindromic substring

摘要: a linear-time algorithm for longest palindromic substringhttp://www.felix021.com/blog/read.php?2040用一个数组 P[i] 来记录以字符S[i]为中心的最长回文子串向左/右扩张的长度(包括S[i]),比如S和P的对应关系:S # 1 # 2 # 2 # 1 # 2 # 3 # 2 # 1 #P 1 2 1 2 5 2 1 4 1 2 1 6 1 2 1 2 1(ps. 可以看出,P[i]-1正好是原字符串中回文串的总长度)//输入,... 阅读全文
posted @ 2013-03-02 23:45 mhgu 阅读(203) 评论(0) 推荐(0) 编辑

决策树、记数排序、基数排序

摘要: //决策树 O(nlgn)const order[][3] = { {0,1,2},{0,2,1},{1,0,2},{1,2,0},{2,0,1},{2,1,0},};int descide_tree_sort(int a1, int a2, int a3;){ if (a1<a2) { if (a2<a3) return 0; //out( a1<a2<a3 ); else { if (a1<a3) return 1; //out( a1<a3<=a2 ); else return 4; //... 阅读全文
posted @ 2013-03-02 22:35 mhgu 阅读(221) 评论(0) 推荐(0) 编辑

找数组的第i个元素

摘要: /* * 返回数组A[p...r]中第i个小的元素, O(n), * 使用快速排序的思想。 * */int randomized_select(int A[], int p, int r, int i){ if (p==r) return A[p]; int q = randomized_partition(A, p, r); int k = q-p+1; if (i<=k) return randomized_select(A, p, q, i); else return randomized_select(A, q+1, r, i-... 阅读全文
posted @ 2013-03-02 21:47 mhgu 阅读(240) 评论(0) 推荐(0) 编辑

快速排序

摘要: /* * A[p...r] 被划分为两部分,A[p...q] 和 A[q+1...r], * A[p...q] 的每个元素都小于等于 A[q+1...r] 中的元素。 * 对子数组递归调用划分方法,整个数组就有序了。 * */void quick_sort(int A[], int p, int r){ int q; if (p<r) q = partition(A, p, r); quick_sort(A, p, q); quick_sort(A, q+1, r);}void exchange(int *a, int *b){ int t = *a... 阅读全文
posted @ 2013-02-28 22:34 mhgu 阅读(182) 评论(0) 推荐(0) 编辑

二叉堆 堆排序 優先隊列

摘要: 二叉堆是一个近似完满二叉树的结构,并同时满足堆的性质:即子结点的键值或索引总是小于(或者大于)它的父节点。通常堆是通过一维数组来实现的。在起始数组为 0 的情形中:父节点i的左子节点在位置 (2*i+1);父节点i的右子节点在位置 (2*i+2);子节点i的父节点在位置 floor((i-1)/2);在堆的数据结构中,堆中的最大值总是位于根节点。堆中定义以下几种操作:堆调整(heapify):将堆的末端子结点作调整,维持堆的性质创建堆(build_heap):将一个无序数组构造为一个堆。堆排序(heap_sort):移除位在第一个数据的根结点,并做堆调整的递归运算#include <st 阅读全文
posted @ 2013-02-27 22:44 mhgu 阅读(178) 评论(0) 推荐(0) 编辑

c++ meta function static_gcd

摘要: meta function,boost mpl,boost::common_factor库,compile time:template <unsigned int x, unsigned int y, bool is_ordered = (x >= y)>struct static_gcd{ static int const value = static_gcd<y, x % y>::value;};template <unsigned int x, unsigned int y>struct static_gcd<x, y, false> 阅读全文
posted @ 2013-02-26 23:11 mhgu 阅读(264) 评论(0) 推荐(0) 编辑

成员函数對象

摘要: template <typename ReturnType, typename ArgType>struct closure_entity_base{ virtual ReturnType operator()(ArgType a)=0; virtual closure_entity_base* clone()const=0;};template <class ClassType, typename ReturnType, typename ArgType>struct closure_entity : closure_entity_base<ReturnType 阅读全文
posted @ 2013-02-26 23:07 mhgu 阅读(215) 评论(0) 推荐(0) 编辑