![](https://img-blog.csdnimg.cn/20201014180756738.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法学习
文章平均质量分 80
tiantangrenjian
这个作者很懒,什么都没留下…
展开
-
连续子串和问题
几个相关的题目1.在数组中找到和最大的lianxu字串原创 2014-09-21 20:17:54 · 2386 阅读 · 0 评论 -
树的孩子兄弟表示法 及遍历实现
以二叉链表为例,#include #include // -------- 树的 孩子-兄弟 存储表示法 ------struct Node{ char data; Node *child; Node *brother;}*CSTree;void PreOrder(Node *head) // 前序遍历{ if(head==NULL)return;原创 2012-01-04 22:00:41 · 16540 阅读 · 0 评论 -
归并排序
归并排序(Merge sort,台湾译作:合并排序)是建立在归并操作上的一种有效的排序算法。该算法是采用分治法(Divide and Conquer)的一个非常典型的应用。分类排序算法数据结构数组最差时间复杂度Θ(nlog n)最优时间复杂度Θ(n)平均时间复杂度Θ(nlog n)最差空间复杂度原创 2012-01-03 15:36:48 · 653 阅读 · 0 评论 -
Strand sort 属于归并排序
Strand sort is a sorting algorithm. It works by repeatedly pulling sorted sublists out of the list to be sorted and merging them with a result array. Each iteration through the unsorted list pulls o原创 2012-01-03 15:52:44 · 1157 阅读 · 0 评论 -
基数排序
基数排序(Radix sort)是一种非比较型整数排序算法,其原理是将整数按位数切割成不同的数字,然后按每个位数分别比较。由于整数也可以表达字符串(比如名字或日期)和特定格式的浮点数,所以基数排序也不是只能使用于整数。基数排序的发明可以追溯到1887年赫尔曼·何乐礼在打孔卡片制表机(Tabulation Machine)上的贡献[1]。它是这样实现的: 将所有待比较数值(正整数)统一为原创 2012-01-03 15:57:58 · 616 阅读 · 0 评论 -
选择排序和堆排序
选择排序(Selection sort)是一种简单直观的排序算法。它的工作原理如下。首先在未排序序列中找到最小元素,存放到排序序列的起始位置,然后,再从剩余未排序元素中继续寻找最小元素,然后放到排序序列末尾。以此类推,直到所有元素均排序完毕。void selectionSort(int data[], int count){ int i, j, min, temp;原创 2011-09-23 21:48:49 · 490 阅读 · 0 评论 -
桶排序和计数排序
桶排序和计数排序桶排序 (Bucket sort)或所谓的箱排序,是一个排序算法,工作的原理是将阵列分到有限数量的桶子里。每个桶子再个别排序(有可能再使用别的排序算法或是以递回方式继续使用桶排序进行排序)。桶排序是鸽巢排序的一种归纳结果。当要被排序的阵列内的数值是均匀分配的时候,桶排序使用线性时间(Θ(n))。但桶排序并不是 比较排序,他不受到 O(n log n) 下限的影响。原创 2012-01-03 15:26:50 · 3467 阅读 · 0 评论 -
拓扑排序 C++实现
【拓扑排序主要思想】 有向图可以拓扑排序的条件是:图中没有环。 具体方法: ⑴ 从图中选择一个入度为0的点加入拓扑序列。 ⑵ 从图中删除该结点以及它的所有出边(即与之相邻点入度减1)。 反复执行这两个步骤,直到所有结点都已经进入拓扑序列。参照严蔚敏的《数据结构(C语言版)》教材,163页有图的邻接表结构定义方法,181-182有课程优先关系的用例和拓扑排原创 2011-09-03 22:01:30 · 10028 阅读 · 6 评论 -
取石子游戏
取石子游戏Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 25176 Accepted: 7961Description有两堆石子,数量任意,可以不同。游戏开始由两个人轮流取石子。游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石原创 2011-10-26 20:53:09 · 4368 阅读 · 0 评论 -
Painter's Problem POJ1681
Painter's ProblemTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 2917 Accepted: 1450DescriptionThere is a square wall which is made of n*n small squ原创 2011-11-19 11:04:47 · 2157 阅读 · 2 评论 -
食物链 POJ1182 -- 并查集
食物链Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 26553 Accepted: 7718Description动物王国中有三类动物A,B,C,这三类动物的食物链构成了有趣的环形。A吃B, B吃C,C吃A。 现有N个动物,以1-N编号。每个原创 2011-12-19 21:06:24 · 10601 阅读 · 1 评论 -
二进制矩阵 POJ1147
Binary codesTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 4925 Accepted: 1869DescriptionConsider a binary string (b1…bN) with N binary digits. Giv原创 2011-11-19 10:29:14 · 2903 阅读 · 0 评论 -
POJ1016 Numbers That Count
Numbers That CountTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 16942 Accepted: 5555Description"Kronecker's Knumbers" is a little company that man原创 2012-10-05 16:13:49 · 1212 阅读 · 0 评论 -
基数排序【经典】
参考 《数据结构》(C语言版)--严蔚敏编著 教材 P288,用C语言实现经典的基数排序算法。用例也参考教材P287.#include #define RADIX 10 //关键字基数,一般为10进制#define MAX_SPACE 100 //数组最大容量/*--- 静态链表 ---*/struct SLCell{ int keys; //关键字 用于存储待排序的数 i原创 2012-01-03 20:20:39 · 817 阅读 · 0 评论 -
【PAT 1003】 Emergency 图论Dijkstra
1003. Emergency (25)时间限制400 ms内存限制32000 kB代码长度限制16000 B判题程序Standard作者CHEN, YueAs an emergency rescue team leader of a city, yo原创 2014-02-18 22:37:20 · 5038 阅读 · 0 评论 -
单源最短路径 Dijkastra算法
给定带权有向图G =(V,E),其中每条边的权是非负实数。另外,还给定V中的一个顶点,称为源。现在要计算从源到所有其它各顶点的最短路长度。这里路的长度是指路上各边权之和。这个问题通常称为单源最短路径问题。1、算法基本思想Dijkstra(迪杰斯特拉)算法是解单源最短路径问题的贪心算法。其基本思想是,设置顶点集合S并不断地作贪心选择来扩充这个集合。一个顶点属于集合S当且仅当从原创 2011-09-01 10:30:35 · 2256 阅读 · 0 评论 -
【PAT 1072】 Gas Station 最短路径Dijsktra
1072. Gas Station (30)时间限制200 ms内存限制32000 kB代码长度限制16000 B判题程序Standard作者CHEN, YueA gas station has to be built at such a locati原创 2014-02-18 14:49:34 · 2912 阅读 · 2 评论 -
【PAT 1017】 Queueing at Bank 模拟算法
1017. Queueing at Bank (25)时间限制400 ms内存限制32000 kB代码长度限制16000 B判题程序Standard作者CHEN, YueSuppose a bank has K windows open for ser原创 2014-02-27 23:40:48 · 2211 阅读 · 1 评论 -
【PAT1018】 Public Bike Management 单源最短路径&路径记录回溯
1018. Public Bike Management (30)时间限制400 ms内存限制32000 kB代码长度限制16000 B判题程序Standard作者CHEN, YueThere is a public bike service in H原创 2014-02-27 22:24:11 · 5253 阅读 · 4 评论 -
Digital Library 字符数组操作
1022. Digital Library (30)时间限制1000 ms内存限制32000 kB代码长度限制16000 B判题程序Standard作者原创 2011-10-18 21:33:20 · 2155 阅读 · 0 评论 -
串的模式匹配 经典KMP算法
KMP算法是字符串匹配的经典算法,由于其O(m+n)的时间复杂度,至今仍被广泛应用。由D.E.Knuth与V.R.Pratt和J.H.Morris同时发现,因此人们称它为克努特——莫里斯——普拉特操作(简称KMP算法)。KMP算法的关键是根据给定的模式串定义一个next函数。next函数包含了模式串本身局部匹配的信息。原创 2011-09-17 18:08:51 · 847 阅读 · 0 评论 -
【PAT 1068】 Find More Coins 背包问题
1068. Find More Coins (30)时间限制150 ms内存限制32000 kB代码长度限制16000 B判题程序Standard作者CHEN, YueEva loves to collect coins from all over t原创 2013-12-15 15:13:25 · 5707 阅读 · 3 评论 -
【PAT 1030】Travel Plan 最短路径Dijkstra
1030. Travel Plan (30)时间限制400 ms内存限制32000 kB代码长度限制16000 B判题程序Standard作者CHEN, YueA traveler's map gives the distances between c原创 2013-12-12 16:20:57 · 1576 阅读 · 0 评论 -
【PAT】1052. Linked List Sorting - map/qsort用法
原题链接 http://pat.zju.edu.cn/contests/pat-a-practise/10521052. Linked List Sorting (25)时间限制400 ms内存限制32000 kB代码长度限制16000 B判题程序Standard原创 2013-10-28 10:23:25 · 1164 阅读 · 1 评论 -
【PAT】1066. Root of AVL Tree (25)
An AVL tree is a self-balancing binary search tree. In an AVL tree, the heights of the two child subtrees of any node differ by at most one; if at any time they differ by more than one, rebalancing is原创 2013-10-20 21:48:44 · 4028 阅读 · 0 评论 -
石子合并问题--直线版
在一条直线上摆着N堆石子,现要将石子有序的合并成一堆,规定如下:每次只能移动相邻的2堆石子合并,合并花费为将的一堆石子的数量。设计一个算法,将这N堆石子合并成一堆的总花费最小(或最大)。 这题类似矩阵连乘,用动态规划解决。代码如下:#include #include #include #include using namespace std;ifstream原创 2011-08-31 12:49:54 · 1522 阅读 · 3 评论 -
排序算法总结
转自 http://zh.wikipedia.org/wiki/排序算法 稳定的冒泡排序(bubble sort) — O(n2)鸡尾酒排序 (Cocktail sort, 双向的冒泡排序) — O(n2)插入排序 (insertion sort)— O(n2)桶排序 (bucket sort)— O(n); 需要 O(k) 额外空间计数排序 (counting sort)转载 2011-09-23 20:46:12 · 707 阅读 · 0 评论 -
Calendar Game POJ1082
Calendar GameTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 3508 Accepted: 1574DescriptionAdam and Eve enter this year's ACM International Collegiate原创 2011-11-05 11:37:57 · 3478 阅读 · 1 评论 -
Crossing River POJ1700
Crossing RiverTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 7873 Accepted: 2879DescriptionA group of N people wishes to go across a river with onl原创 2011-11-19 11:08:49 · 2166 阅读 · 1 评论 -
大整数乘法 求阶乘
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=1042N!Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Ot原创 2011-09-28 22:20:53 · 1662 阅读 · 0 评论 -
Crashing Robots POJ2632
Crashing RobotsTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 4556 Accepted: 1991Description原创 2011-09-27 21:14:54 · 2978 阅读 · 0 评论 -
石子合并问题---圆形版
在一个圆形操场的四周摆放N堆石子(N≤100),现要将石子有次序地合并成一堆。规定每次只能选相邻的两堆合并成新的一堆,并将新的一堆的石子数,记为该次合并的得分。编一程序,由文件读入堆数N及每堆石子数(≤20)选择一种合并石子的方案,使得做N-1次合并,得分的总和最小;选择一种合并原创 2011-08-31 13:14:27 · 2626 阅读 · 0 评论 -
Y2K Accounting Bug POJ2586
Y2K Accounting BugTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 5559 Accepted: 2712Descripti原创 2011-09-25 15:02:33 · 4779 阅读 · 0 评论 -
POJ 1328 Radar Installation
Radar InstallationTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 28083 Accepted: 6152Descript原创 2011-09-24 21:26:47 · 449 阅读 · 0 评论 -
Power of Cryptography POJ2109
Power of CryptographyTime Limit: 1000MS Memory Limit: 30000KTotal Submissions: 11348 Accepted: 5847Descr原创 2011-09-25 14:14:41 · 945 阅读 · 0 评论 -
Printer Queue(打印队列)POJ3125
Printer QueueTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 2817 Accepted: 1523Description原创 2011-09-26 11:34:01 · 4752 阅读 · 0 评论 -
Parencodings POJ1068解题报告
ParencodingsTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 12950 Accepted: 7675Description原创 2011-09-26 10:31:04 · 892 阅读 · 0 评论 -
交换排序
交换排序法冒泡排序 | 鸡尾酒排序 | 奇偶排序 | 梳排序 | Gnome sort | 快速排序鸡尾酒排序 等于是冒泡排序的轻微变形。不同的地方在于从低到高然后从高到低,而冒泡排序则仅从低到高去比较序列里的每个元素。他可以得原创 2011-09-23 20:55:42 · 636 阅读 · 0 评论 -
LC-Display POJ1102
LC-DisplayTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 12641 Accepted: 4970DescriptionA friend of you has just bought a new computer. Until now,原创 2011-12-03 16:39:39 · 1289 阅读 · 0 评论 -
添字成回文词 POJ1159
PalindromeTime Limit: 3000MS Memory Limit: 65536KTotal Submissions: 39691 Accepted: 13485DescriptionA palindrome is a symmetrical string, that is, a string re原创 2011-11-19 10:43:18 · 1186 阅读 · 0 评论