现在位置: 首页 > adversity发表的所有文章
  • 09月
  • 03日
算法 ⁄ 共 1164字 评论关闭
题意:给你n和h,问有多少棵n个节点高度为h的二叉搜索树(标号为1-n,只有一个节点的树高为0),答案对10^9+7取模。 思路:设dp[ n ][ h ]为 n 个节点高度不超过 h 的二叉搜索树的个数。那么dpn,h=∑i=0n-1dpi,h−1⋅dpn−i-1,h−1   即选定一个点,枚举左子树的个数为 i ,剩余右子树的个数即为n - 1 - i 。详见代码: /********************************************************* file name: spoj8549.cpp author : kereo create time: 2014年12月05日 星期五 22时45分10秒 **********************************************......
阅读全文
  • 08月
  • 28日
综合 ⁄ 共 1665字 评论关闭
想平时写 C++ 时,从文件中按指定格式读入数据多方便。。 给自己写个 Java 的。。 package lib.com.chalex.www; import java.io.BufferedReader; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; /** * @author Jiechao * */ public class SReader { /** * @remark Constructor. */ public SReader(String filepath) { cur = 0; try { String line = new String(); reader = new BufferedReader(new InputStreamRea......
阅读全文
  • 08月
  • 11日
综合 ⁄ 共 1174字 评论关闭
  /* 实现整型数组的循环右移 cycleMoveR1:临时空间比较大,但是时间复杂度为O(1) cycleMoveR2:临时空间比较小,时间复杂度为O(n) */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <assert.h> // 数组循环右移moveLen个 int cycleMoveR1(int arr[], int len, int moveLen) { assert(len > 0 && moveLen > 0); moveLen = moveLen % len; int *p = malloc(moveLen * sizeof(int)); if(NULL == p) return 0; memcpy(p, arr+le......
阅读全文
  • 04月
  • 25日
编程语言 ⁄ 共 1248字 评论关闭
/* 二进制转换为十进制 */ #include<stdio.h> #include<stdlib.h> #define INCREMENT 8 typedef char Elemtype; typedef struct Stack { Elemtype *top; Elemtype *base; int stackSize; }Stack; Stack *initStack( int n ) //栈初始化函数 { Stack *s = (Stack *)malloc(sizeof(Stack)); s -> base = ( Elemtype * )malloc( sizeof(Elemtype) * n ); if ( s -> base == NULL ) exit(0); s -> top = s -> base; s -> stackSize = n; return s; } void Push( Stack *s, Elemtype......
阅读全文
  • 02月
  • 16日
综合 ⁄ 共 2891字 评论关闭
Catenyms Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9887   Accepted: 2583 Description A catenym is a pair of words separated by a period such that the last letter of the first word is the same as the last letter of the second. For example, the following are catenyms: dog.gopher gopher.rat rat.tiger aloha.aloha arachnid.dog A compound catenym is a sequence of three or more words separated by periods such that each adjacent pair of words forms a catenym. Fo......
阅读全文
  • 12月
  • 20日
综合 ⁄ 共 1986字 评论关闭
@维基百科 卡塔兰数是組合數學中一個常在各種計數問題中出現的數列。以比利時的數學家欧仁·查理·卡塔兰 (1814–1894)命名。 卡塔兰数的一般項公式為  前幾項為 (OEIS中的数列A000108): 1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786, 208012, 742900, 2674440, 9694845, 35357670, 129644790, 477638700, 1767263190, 6564120420, 24466267020, 91482563640, 343059613650, 1289904147324, 4861946401452, 18367353072152, 69533550916004, 263747951750360, 1002242216651368, 3814986502092304, 1454463603922......
阅读全文
  • 09月
  • 25日
综合 ⁄ 共 588字 评论关闭
1. 问题详细描述如下。 下图显示对比结果中,两侧的aaa.xml是一模一样,会话中却以红色标识出来,说明两者不同。 将aaa.xml打开之后显示如下:里面的内容完全一样。   关闭aaa.xml的会话之后,aaa.xml又变成一样的了。Aaa.xml变成了黑色。   一直以来都苦恼于这个问题很久,我肯定这一定是个配置问题,但是一直也没有时间去研究,网上搜了搜也没有轻易的找到合理的解决方案,今天要比较两个很大的文件夹,就半天出不来结果,然后所有的文件夹还要一个一个的打开才能看出来两个文件是否都一样。   2.原因分析: 今......
阅读全文
  • 09月
  • 21日
综合 ⁄ 共 1101字 评论关闭
前言 Redis源码中的文件事件轮询,对于linux采用了epoll而非select。故而对epoll产生了兴趣,查资料发现原来epoll比select高效不少。下面是看了几篇文章的一点心得。目前还没真正的看epoll源码,看起来源码比select复杂,等以后有时间在好好啃一啃。 几个关键点 1. epoll是linux独有的。 2. 系统启动的时候,会构建特殊的文件系统。 epfd = epoll_create( MAXEPOLLSIZE );      就会在这个虚拟的epoll文件系统里创建一个file结点:kdpfd。可以通过目录查看:/proc/进程id/epfd 3. 系统为epoll在内核的slab高速缓存中分配空间,......
阅读全文
  • 08月
  • 28日
综合 ⁄ 共 212字 评论关闭
问题:从ClearCase上checkout下来的工程,里面的文件属性都被设置成readonly了,在Configure Build Path中添加了jar包的引用后,需要clean该工程才能生效,可下次打开Eclipse的时候,该jar包还是没有被添加到Build Path中。 原因:.classpath文件时readonly的,所以修改Build Path不能生效。 解决:修改.classpath文件属性,去掉readonly。
阅读全文
  • 08月
  • 04日
综合 ⁄ 共 33字 评论关闭
今天恰好是10月24日 程序员节 开通个博客 记录一些开发历程 问题 总结。
阅读全文
  • 05月
  • 29日
综合 ⁄ 共 1291字 评论关闭
(unresolved external symbol __endthreadex解决办法)   1、新建控制台程序:       2、添加源代码如下: #include <afx.h> #include <stdio.h> int main() { int lo, hi; CString str; CStdioFile pFile; pFile.Open("FIBO.DAT", CFile::modeWrite | CFile::modeCreate| CFile::typeText); str.Format("%s/n", "Fibonacci sequencee, less than 100 :"); printf("%s", (LPCTSTR) str); pFile.WriteString(str); lo = hi = 1; str.Format("%d/n", lo); prin......
阅读全文
  • 05月
  • 20日
综合 ⁄ 共 51字 评论关闭
http://blog.csdn.net/sutine/article/details/5653137
阅读全文