<?xml version="1.0" encoding="gbk"?>
<rss version="2.0">
  <channel>
    <title>曲径通幽论坛 - Algorithm</title>
    <link>http://www.groad.net/bbs/forum.php?mod=forumdisplay&amp;fid=32</link>
    <description>Latest 20 threads of Algorithm</description>
    <copyright>Copyright(C) 曲径通幽论坛</copyright>
    <generator>Discuz! Board by Comsenz Inc.</generator>
    <lastBuildDate>Mon, 25 May 2026 21:36:36 +0000</lastBuildDate>
    <ttl>60</ttl>
    <image>
      <url>http://www.groad.net/bbs/static/image/common/logo_88_31.gif</url>
      <title>曲径通幽论坛</title>
      <link>http://www.groad.net/bbs/</link>
    </image>
    <item>
      <title>unicode 转 utf-8 算法</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=8148</link>
      <description><![CDATA[utf-8 是 unicode 的一种实现形式，有时会遇到纯的 unicode 编码，比如 0x8d44 ，这里提供一个实现转换的程序段：[mw_shl_code=c,true]#include 
#include 
#include 

int main(int argc, char **argv)
{
        char dest[8] ={ 0 };
        char *b = dest; ...]]></description>
      <category>Algorithm</category>
      <author>beyes</author>
      <pubDate>Tue, 19 Nov 2013 06:40:27 +0000</pubDate>
    </item>
    <item>
      <title>去掉字符串中的空格符</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=7879</link>
      <description><![CDATA[在某些情况下，需要去掉字符串中的空格符，比如将 \&quot;hello world\&quot; 写成 \&quot;helloworld\&quot; 。
 
下面示例程序给出该问题的一个解决算法：
[mw_shl_code=cpp,true]#include 
#include 

void eatspaces(char *str)
{
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;int i =  ...]]></description>
      <category>Algorithm</category>
      <author>beyes</author>
      <pubDate>Sun, 07 Jul 2013 12:25:50 +0000</pubDate>
    </item>
    <item>
      <title>字符串替换</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=7136</link>
      <description><![CDATA[假设有一个字符串，需要将里面包含 sim1 替换为 sim 。
 
这个事情如果用正则表达式来处理，那极为简单。下面使用 C 语言来实现，代码如下：
[mw_shl_code=cpp,true]#include 
#include 

int main()
{
&#160;&#160;&#160;&#160;char str[] = \&quot;abcdefsimokaeikjfasim1ek ...]]></description>
      <category>Algorithm</category>
      <author>beyes</author>
      <pubDate>Mon, 04 Jun 2012 13:25:25 +0000</pubDate>
    </item>
    <item>
      <title>任意进制数的转换(二进制到三十六进制)</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=5761</link>
      <description><![CDATA[任意进制数的转换在一些脚本语言里比较容易实现，基本上是用了某类中的某个方法，比如 javascript 中的 toString() 方法。

一般情况下，转换范围在 2~36 进制之间。下面是 C 语言的一个实现。转换的思路很直接，利用的是逐个求余。

测试代码：
[mw_shl_code=cpp,true] ...]]></description>
      <category>Algorithm</category>
      <author>beyes</author>
      <pubDate>Wed, 28 Dec 2011 03:19:21 +0000</pubDate>
    </item>
    <item>
      <title>使用 (x&amp;y) + ((x^y)&gt;&gt;1) 求平均数</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=5253</link>
      <description><![CDATA[在一个面试题里见到这么一道题：
 
下面的代码：

当 x 为 729，y 为 271 时函数的返回值是多少？
 
思路最简单也最直接的就是将 x 和 y 都先转换为二进制，然后老老实 ...]]></description>
      <category>Algorithm</category>
      <author>beyes</author>
      <pubDate>Tue, 15 Nov 2011 15:20:14 +0000</pubDate>
    </item>
    <item>
      <title>凯撒加密算法</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=4681</link>
      <description><![CDATA[凯撒加密算法可以对字母字母进行简单的转换加密，方法是：字母的 ASCII 值加上某个数值后再和 256 做模运算。这样加密后的文件可能含有不可打印的字符，而且行结束，字符串结束和其它的控制字符都会被更改。解密时，只需要将转换时指定的值用负值表示，或者使用 256 减 ...]]></description>
      <category>Algorithm</category>
      <author>beyes</author>
      <pubDate>Sat, 10 Sep 2011 09:25:15 +0000</pubDate>
    </item>
    <item>
      <title>大数的阶乘</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=4555</link>
      <description><![CDATA[由于类型的限制，大数的阶乘会导致变量溢出，所以无法直接得到结果，比如求 100 的阶乘即使是 64 位的 long long 类型也不行。

如果使用 python 语言，那么得到 100 的阶乘最为容易：
[mw_shl_code=text,true]#!/usr/bin/python

import math

print math.factorial(10 ...]]></description>
      <category>Algorithm</category>
      <author>beyes</author>
      <pubDate>Thu, 01 Sep 2011 03:59:03 +0000</pubDate>
    </item>
    <item>
      <title>gdbm hash 算法</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=4196</link>
      <description><![CDATA[原来使用于 gdbm 数据库的源码中，下面代码片段来自 linux 内核代码中的 modpost 工具源码 modpost.c ：
[mw_shl_code=cpp,true]
#define SYMBOL_HASH_SIZE 1024

static struct symbol *symbolhash[SYMBOL_HASH_SIZE];
... ...
/* This is based on the hash agorithm  ...]]></description>
      <category>Algorithm</category>
      <author>beyes</author>
      <pubDate>Mon, 25 Jul 2011 03:40:17 +0000</pubDate>
    </item>
    <item>
      <title>FNV 哈希算法</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=4078</link>
      <description><![CDATA[FNV哈希函数，有三种FNV-0（已废弃），FNV-1， FNV-1a。

FNV-1和FNV-1a算法对于最终生成的哈希值（hash）有一定限制：

1，hash是无符号整型

2，hash的位数（bits），应该是2的n次方（32，64，128，256，512，1024），一般32位的就够用了。

FNV-1形式：
[mw_shl_code ...]]></description>
      <category>Algorithm</category>
      <author>beyes</author>
      <pubDate>Tue, 12 Jul 2011 06:19:20 +0000</pubDate>
    </item>
    <item>
      <title>汉明重量</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=3517</link>
      <description><![CDATA[在 linux 内核里，在计算 CPU 个数时用到了 hweight32 这个函数，这个函数就是汉明重量的计算方法。对于二进制串来说，它就是计算这个二进制串里含有多少个 1 。hweight32() 函数实现如下：
[mw_shl_code=cpp,true]unsigned int hweight32(unsigned int w)
{
&#160;&amp;#16 ...]]></description>
      <category>Algorithm</category>
      <author>beyes</author>
      <pubDate>Wed, 11 May 2011 13:28:04 +0000</pubDate>
    </item>
    <item>
      <title>peterson 算法</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=3255</link>
      <description><![CDATA[peterson 算法较 dekker 算法(关于 dekker 算法分析见：http://www.groad.net/bbs/read.php?tid-3251.html)来讲显得更为简洁。

对于 P0 进程的代码为：
[mw_shl_code=cpp,true]    flag[0] = 1;   
    turn = 1;       
    while (flag[1] == 1 &amp;&amp; turn == 1)
    {
 ...]]></description>
      <category>Algorithm</category>
      <author>beyes</author>
      <pubDate>Tue, 22 Mar 2011 03:23:55 +0000</pubDate>
    </item>
    <item>
      <title>Dekker 算法</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=3251</link>
      <description><![CDATA[初步设想是这样的：
定义全局布尔变量 turn ，其值 0, 1 分别表示 P0 和 P1 进程占有了临界区。

对于 P0 进程：
[mw_shl_code=cpp,true]bool turn;
/* 对于 P0 进程 */
while (turn != 0)
;   /*什么都不做,忙等待*/

/*********************/
/*  临界区代码    */
/* ...]]></description>
      <category>Algorithm</category>
      <author>beyes</author>
      <pubDate>Mon, 21 Mar 2011 15:33:30 +0000</pubDate>
    </item>
    <item>
      <title>CRC16-CCITT 算法及 C 程序</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=3130</link>
      <description><![CDATA[CRC16-CCITT 是 CRC16 的欧版标准。其多项式为：x16 + x12 + x5 + 1    简记为 0x1201 。求 CRC 就是对多项式求余，其公式为：P(x) = Q(x) * G(x) + R(x)其中，P(x) 为要对其求 CRC 的数据，Q(x) 为商，G(x) 为多项式(如上面的 CRC16-CCITT)，R(x) 为余数(也就是要求的  ...]]></description>
      <category>Algorithm</category>
      <author>beyes</author>
      <pubDate>Fri, 18 Feb 2011 02:30:14 +0000</pubDate>
    </item>
    <item>
      <title>埃拉托色尼筛法多线程找素数</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=2811</link>
      <description><![CDATA[埃拉托色尼筛法 
利用埃拉托色尼筛法寻找 2~n 之间的素数，方法是去掉所有 2 的倍数，再去掉所有 3 的倍数，以此类推，最后剩下的就是素数。 

下面程序使用多线程来完成：]]></description>
      <category>Algorithm</category>
      <author>beyes</author>
      <pubDate>Wed, 20 Oct 2010 14:36:34 +0000</pubDate>
    </item>
    <item>
      <title>递归法创建多层目录</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=2150</link>
      <description><![CDATA[此程序适用于linux平台，可以在命令行参数指定每一层创建目录数，以及指定创建的目录的深度。算法如下：]]></description>
      <category>Algorithm</category>
      <author>beyes</author>
      <pubDate>Thu, 03 Jun 2010 11:14:23 +0000</pubDate>
    </item>
    <item>
      <title>算法效率的质量与时间复杂度</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=1169</link>
      <description><![CDATA[算法执行时间需要通过依据该算法编制的程序在计算机上运行时所消耗的时间来度量。而度量一个程序的执行时间通常有两种方法：

(1)事后统计法
计算机内部都有计时功能，不同算法的程序可通过一组或若干组相同的统计数据以分辨优劣。这种方法有两个缺陷：一个是必须运行依 ...]]></description>
      <category>Algorithm</category>
      <author>beyes</author>
      <pubDate>Sat, 12 Sep 2009 12:50:24 +0000</pubDate>
    </item>
    <item>
      <title>矩阵与矩阵相乘</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=1168</link>
      <description><![CDATA[矩阵与矩阵相乘应满足的条件：
1、矩阵 A 的列数必须等于矩阵 B 的行数；
2、设矩阵 C 是矩阵A 与 矩阵B 相乘结果存放的矩阵，那么矩阵 C 的行数等于矩阵A 的行数，矩阵C 的列数等于矩阵 B 的列数；
3、矩阵C 中的第 i 行 j 列的元素是 矩阵A 中的第 i 行元素与 矩阵B  ...]]></description>
      <category>Algorithm</category>
      <author>beyes</author>
      <pubDate>Sat, 12 Sep 2009 08:36:34 +0000</pubDate>
    </item>
    <item>
      <title>二分法查找一维数组</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=1166</link>
      <description><![CDATA[代码：]]></description>
      <category>Algorithm</category>
      <author>beyes</author>
      <pubDate>Fri, 11 Sep 2009 04:02:08 +0000</pubDate>
    </item>
    <item>
      <title>字符串的插入</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=982</link>
      <description><![CDATA[实现一个字符串插入另外一个字符串中。程序中没做很严格的检查，算法或许显得冗长拖沓。

完整代码如下：
 
运行及输出：]]></description>
      <category>Algorithm</category>
      <author>beyes</author>
      <pubDate>Fri, 31 Jul 2009 05:07:26 +0000</pubDate>
    </item>
    <item>
      <title>冒泡法</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=977</link>
      <description><![CDATA[code:

[mw_shl_code=cpp,true]#include 


#define MAX 8


int main()
{
        int b[MAX] = {10, 33, 63, 8, 91, 100, 22, 15};
        int i, k, temp;


        for (i = 0; i &lt; MAX - 1; i++)
                for (k = i + 1; k &lt; MAX; k++)
                ...]]></description>
      <category>Algorithm</category>
      <author>beyes</author>
      <pubDate>Mon, 27 Jul 2009 14:11:12 +0000</pubDate>
    </item>
  </channel>
</rss>