02 2012 档案
摘要:在《Fibonacci数计算中的两个思维盲点及其扩展数列的通用高效解法》提到了一维的求解m^n.算是比较快的,作个备份。最基本的求解,没有考虑为负数的情况,下同int pow0(int m,unsigned int n){ int result = 1; while(n >0) { result *= m; --n; } return result;}改进版求解迭代int pow1(int m, unsigned int n){ int result = 1; int factor = m; while (n) { ...
阅读全文
摘要:编译一份源码,提示有错误error: invalid conversion from ‘__pthread_t*’ to ‘pid_t’initializing argument 1 of ‘int kill(pid_t, int);定位到源码kill((p->_pNodeBuf[p->_cur_num-1])._th_id,SIGKILL);即kill的参数类型为pid_t,而实际上传递的为pthread_t,这种情况下gcc报错提示无法转换。在网上搜索到有个函数pthread_kill(pthread_t pid,int sig);替换下即可。但是有个问题,pthread_t
阅读全文
摘要:从项目webalizer抓取到一个有用的关于儒略日(Julian Day)的函数。关于"儒略日数"介绍参考http://blog.sina.com.cn/s/blog_53027c620100mtii.html/*****************************************************************//**//* JDATE - Julian date calculator *//**//* Calculates the number of days since Jan 1, 0000. ...
阅读全文
摘要:看到一篇中文文章《C/C++, Java: Java的new[]与C++的new[]》很有意思。public class Test extends JPanel { private static final long serialVersionUID = 4767050156491994899L; public static void main(String[] args) { AnimApp[] array = new AnimApp[3]; // 没有执行构造函数, 在这里只是申请了空间. array[0] = new AnimApp(3); // ...
阅读全文
摘要:看到一篇文章《Extra, Extra - Read All About It: Nearly All Binary Searches and Mergesorts are Broken》说的是很多二分查找都有bug,包括《编程珠玑》上给出的实现。这个bug也曾经出现在java.util中。典型的Java版实现是int binarySearch(int a[], int key, int length) { int low = 0; int high = length - 1; while (low <= high) { int mid = (low + high) / 2; int m
阅读全文
摘要:以前只闻RTTI(Run-Time Type Identification,运行时类型识别),并未通达。参考文章《typeid详解》的相关内容,获知了些知识。如下是所有的测试代码源码说明一切。typeid
阅读全文
摘要:刷水题判断有多少个素数。关键点避免超时。http://acm.hdu.edu.cn/showproblem.php?pid=2138View Code #include <stdio.h>#include <math.h>int isPrimer(unsigned int n ){ int i ; unsigned int m = sqrt(n); for(i = 2; i <= m; ++i) { if(!(n % i )) break; } return i > m;}int main(){ int n,m; ...
阅读全文

浙公网安备 33010602011771号