矩阵转置问题

Posted on Wed 13 July 2011 in miscLeave a comment

如果可以使用额外空间,编程实现矩阵转置是十分简单的,这里就不再做过多的讨论。如何在不使用额外空间的条件下转置矩阵呢?下面会分两种情况来进行讨论。\ 1.方阵的转置\ 方阵是N*N的矩阵,通过交换m[i][j]与m[j][i]的值,就可以实现方阵的转置。\ 2.非方阵的转置\ 假设有N*M的矩阵,其中N!=M,怎么来实现in-place的transposition呢?\ 考虑有如下的矩阵\ |1,2|\ |3,4|\ |5,6|\ 该矩阵在内存中是按[1,2,3,4,5,6]的顺序存放。\ 转置之后则有\ |1,3,5|\ |2,4,6|\ 该矩阵在内存中是按[1 ...

Continue reading

购入一kindle 3

Posted on Fri 18 February 2011 in miscLeave a comment

兔年考虑购入一台电纸书,经过一段时间的比较,最终选择了kindle 3(觉得其性价比很高,相比国内产品价格也不存在劣势)。在淘宝上找的商家,去现场提的货,就在鼎好二期地下一层。\ btw:那个商家的销售小姐很漂亮。\ kindle
3\

货拿到手后,迫不及待地开始使用。kindle十分轻薄,e-ink屏幕很有纸张的感觉,看起来十分舒服。略感遗憾的是kindle3的屏幕较小,影响pdf的阅读。中文在kindle原生的系统上经常出现“口”,十分影响阅读。为了让kindle更好地支持中文,安装了“多看”系统。“多看”系统不仅可以更好地支持中文,还提供了许多实用的功能,并且与原生系统互不影响。以后有时间研究下“多看”系统,看其是如何对kindle进行破解的。上周Amazon出了kindle ...

Continue reading

Hash table

Posted on Sun 28 November 2010 in miscLeave a comment

Hash table定义(摘自wikidpedia)\ In computer science, a hash table or hash map is a data structure that uses a hash function to map identifying values, known as keys (e.g., a person's name), to their associated values (e.g., their telephone number).\ hash table简单来说就是一种数据结构,可以通过一个key来查询对应的value值(一般情况下效率是很高的)。

记得以前大学时,老师曾出过这样的一道题目 ...

Continue reading

最大流与最小割

Posted on Fri 26 November 2010 in miscLeave a comment

最大流与最小割定义(摘自wikipedia)\ In optimization theory, the max-flow min-cut theorem states that in a flow network, the maximum amount of flow passing from the source to the sink is equal to the minimum capacity which when removed in a specific way from the network causes the situation that no flow ...

Continue reading

二分图最大匹配

Posted on Tue 23 November 2010 in miscLeave a comment

二分图定义(摘自wiki)\ In the mathematical field of graph theory, a bipartite graph (or bigraph) is a graph whose vertices can be divided into two disjoint sets U and V such that every edge connects a vertex in U to one in V; that is, U and V are independent sets ...

Continue reading

python解析html

Posted on Wed 10 November 2010 in miscLeave a comment

python自带有一个html的解析库,但这个库的功能有限,而且对网页中异常情况的处理不好。\ 后来在网上找到一个叫[BeautifulSoup](http://www.crummy.com/software/BeautifulSoup/)的网页解析库,这个库利用了正则表达式对网页进行处理,能比较完美地处理异常情况,还支持unicode。\ 除此之外还有lxml等python库。\ 下面是BeautifulSoup的一些例子,是从官网摘过来的。更多详细信息可以看[官方文档](http://www.crummy.com/software/BeautifulSoup/documentation.html),有[中文版](http://www.crummy.com/software/BeautifulSoup/documentation.zh.html)\

Continue reading

判断两个路径(文件或文件夹)所指的内容是否相同

Posted on Mon 25 October 2010 in miscLeave a comment

思路:\ 1.判断文件是否都存在\ 2.判断类型是否相同(是否都是文件夹,是否都是文件)\ 3.如果是文件, 比较文件的二进制内容\ 4.如果是文件夹:\ 4.1 列出文件夹下的所有文件,并按文件名排序\ 4.2 依次递归比较所有文件

代码:\

Continue reading

python实现daemon程序

Posted on Thu 21 October 2010 in miscLeave a comment

为了实现python程序的daemon运行,找到了如下的代码。通过继承这个类,就能实现daemon程序。\ 除此之外还可以用screen,或nohup来实现。\ 代码出处:http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/

import sys, os, time, atexit
from signal import SIGTERM

class Daemon:
    """
   A generic daemon class.

 Usage: subclass the Daemon class and override the run() method
    """
   def __init__(self, pidfile, stdin='/dev/null', stdout='/dev/null ...
Continue reading

获取自增长id(mysql)

Posted on Wed 20 October 2010 in miscLeave a comment

java

PreparedStatement ps =conn.prepareStatement("insert into table (col) values (?)", Statement.RETURN_GENERATED_KEYS);
ps.getGeneratedKeys();

sql

最后插入的id

select last_insert_id();

下一个id

SHOW TABLE STATUS LIKE "table_name";//auto_increment列
Continue reading

ttserver相关

Posted on Wed 20 October 2010 in miscLeave a comment

ttserver在32位机器上支持超过4g的数据库,编译时加上如下的选项:\ --enbale-off64

Continue reading