
数据结构与算法
文章平均质量分 79
hwb506
这个作者很懒,什么都没留下…
展开
-
求最大值,递归与非递归方法
#include #include #include int recursive(unsigned int num, int data[]){ int nextdata, curdata = *data; if (num == 1) { return curdata; } nextdata = recursive(--num, ++data); return curdata > nextdata ? curdata : nextdata;}原创 2010-08-28 11:47:00 · 704 阅读 · 0 评论 -
TopCoder 2 Lottery
Problem Statement In most states, gamblers can choose from a wide variety of different lottery games. The rules of a lottery are defined by two integers (choices andblanks) and two bool原创 2012-04-29 01:43:25 · 834 阅读 · 0 评论 -
TopCoder 3 PenLift
Problem Statement NOTE: There are images in the examples section of this problem statement that help describe the problem. Please view the problem statement in the HTML window to view the原创 2012-04-29 11:59:10 · 795 阅读 · 0 评论 -
TopCoder 练习1 加密转换
Problem Statement Let's say you have a binary string such as the following: 011100011 One way to encrypt this string is to add to each digit the sum of its adjacent digits. For exampl原创 2012-04-25 11:01:14 · 563 阅读 · 0 评论 -
贪心算法(Greedy algorithm)
转自:http://www.cnblogs.com/chinazhangjie/archive/2010/11/23/1885330.html顾名思义,贪心算法总是作出在当前看来最好的选择。也就是说贪心算法并不从整体最优考虑,它所作出的选择只是在某种意义上转载 2011-08-31 21:03:56 · 1094 阅读 · 0 评论 -
Sample of STL(Vector):begin and rbegin
#include #include #include #include #include #include using namespace std;class ID{ friend bool operator转载 2011-04-25 09:50:00 · 1038 阅读 · 0 评论 -
STL中的7种容器
<br />转自:http://www.cppblog.com/kevinjee/archive/2008/12/01/68314.aspx<br /> <br />容器(Container)的概念的出现早于模板(template),它原本是一个计算机科学领域中的一个重要概念,但在这里,它的概念和STL混合在一起了。下面是在STL中出现的7种容器:<br /><br />vector(向量)——STL中标准而安全的数组。只能在vector 的“前面”增加数据。<br /><br />deque(双端转载 2011-04-23 15:44:00 · 564 阅读 · 0 评论 -
螺旋队列算法分析
<br />转自:http://blog.youkuaiyun.com/yhmhappy2006/archive/2008/09/16/2934435.aspx<br /><br />螺旋队列的样子如下图:<br /> <br /><br /> <br /> <br />两大规律:<br />1。螺旋规律(红线)<br />2。奇数平方规律(紫线)<br /> <br />问题描述:<br /> <br />设1的坐标是(0,0),的方向向右为正,y方向向下为正,例如,7的坐标为(-1,-1),<br />2的坐标为(转载 2011-03-14 23:21:00 · 402 阅读 · 0 评论 -
Undirected graphs representation
<br /> <br />转自:http://www.algolist.net/Data_structures/Graph/Internal_representation<br />There are several possible ways to represent a graph inside the computer. We will discuss two of them: adjacency matrixand adjacency list.Adjacency matrix<br />Each转载 2011-03-11 16:41:00 · 766 阅读 · 0 评论 -
深度优先搜索算法(Depth first search)
<br /> Depth-first search (DFS) for undirected graphs<br />Depth-first search, or DFS, is a way to traverse the graph. Initially it allows visiting vertices of the graph only, but there are hundreds of algorithms for graphs, which are based on DFS. Therefo转载 2011-03-11 15:57:00 · 1060 阅读 · 0 评论 -
哈希表及其查找
<br /><br />哈希译自“hash”一词,也称为散列或杂凑。<br /> 哈希表查找的基本思想是:根据当前待查找数据的特征,以记录关键字为自变量,设计一个哈希函数,依该函数按关键码计算元素的存储位置,并按此存放;查找时,由同一个函数对给定值key计算地址,将key与地址单元中元素关键码进行比较,确定查找是否成功。哈希方法中使用的转换函数称为哈希函数(杂凑函数),按这个思想构造的表称为哈希表(杂凑表)。<br /> 对于n个数据元素的集合,总能找到关键码与存放地址一一对应的函数。若最大关键为m,可转载 2011-03-07 21:00:00 · 1149 阅读 · 0 评论 -
详细解说STL hash_map系列
<br />详细解说STL hash_map系列0 为什么需要hash_map1 数据结构:hash_map原理2 hash_map 使用2.1 一个简单实例2.2 hash_map 的hash函数2.3 hash_map 的比较函数2.4 hash_map 函数3 相关hash容器4 其他4.1 hash_map和map的区别在哪里?4.2 什么时候需要用hash_map,什么时候需要用map?4.3 如何在hash_map中加入自己定义的类型?4.5为什么hash_map不是标准的?4.6 有学习使用h转载 2011-03-07 20:55:00 · 437 阅读 · 0 评论 -
计算机学习方法
<br />http://blog.youkuaiyun.com/ChinaCzy/archive/2010/05/30/5632089.aspx转载 2011-03-08 22:28:00 · 387 阅读 · 0 评论 -
简单的[0/1]背包问题 分别用递归与非递归实现
<br />#include <iostream>using namespace std;bool Kanpsack(int kanpsack_weight, int object_weight[], int object_num){ cout << kanpsack_weight << " " << *object_weight << " " << object_num << endl; if (kanpsack_weight == *object_weight) { ret原创 2010-08-31 21:53:00 · 550 阅读 · 0 评论 -
Spanning Tree
转自:http://www.csie.ntnu.edu.tw/~u91029/SpanningTree.html先收藏了,以后好好看一下。Spanning Tree / Spanning Forest中譯「生成樹」,從一張圖上分離出一棵包含圖上所有點的樹,便是這張圖的生成樹。一張圖的生成樹可能會有很多種。當一張圖完全連通,必然有生成樹。當一張圖有部份不連通,則沒有生转载 2014-04-03 20:53:14 · 902 阅读 · 0 评论