Algorithm
文章平均质量分 73
小白笑苍
沉默是一种生活方式。
展开
-
牛顿法求平方根
今天在知乎上看到求平方根的方法,除了常规的二分查找,有人说了牛顿法和magic number。牛顿法涉及到很多数学计算(泰勒,求导之类的),没理解原理。先把步骤看了。 求一个整数x的平方根,先随机取个y,如果不对或是精度没达到,循环令 y = (y + x/y)/2.double sqr(double n) { double k = 1.0; //可任取转载 2016-05-04 23:57:38 · 412 阅读 · 0 评论 -
The shuffle algorithm
Today I used the python’s API shuffle(random.shuffle) to resort a list and I am wondering the related algorithm so I find some materials。Fisher-Yates shuffleWrite down the numbers from 1 through N....原创 2019-03-15 16:28:02 · 166 阅读 · 0 评论 -
From good to great. How to approach most of DP problems.
I find an article about the DP in the leetcode and it is fantastic. The URL of the origin:From good to great. How to approach most of DP problems.There is some frustration when people publish their p...转载 2019-03-04 14:50:25 · 151 阅读 · 0 评论 -
爬山算法 ( Hill Climbing )/模拟退火(SA,Simulated Annealing)
一. 爬山算法 ( Hill Climbing )爬山算法是一种简单的贪心搜索算法,该算法每次从当前解的临近解空间中选择一个最优解作为当前解,直到达到一个局部最优解。爬山算法实现很简单,其主要缺点是会陷入局部最优解,而不一定能搜索到全局最优解。假设C点为当前解,爬山算法搜索到A点这个局部最优解就会停止搜索,...转载 2018-12-26 13:58:07 · 1221 阅读 · 0 评论 -
Painting with Tensorflow
It is an open source library by tensorflow. Here is the article: https://link.zhihu.com/?target=http%3A//arxiv.org/abs/1508.06576I am learning from it right now.Here is the demo code:from __futu原创 2018-02-07 11:02:05 · 268 阅读 · 0 评论 -
矩阵乘法编写,从文件输入输出
题目matrixA.txt , shape(1,50) matrixB.txt , shape(50,10) 1. 讀取matrixA.txt,matrixB.txt中的矩陣 2. 進行矩陣乘法 - matrixA * matrixB 3. 將得到的矩陣數值,由小到大排序後輸出至ans_one.txt,每个数字要换行文件样式matrixA.txt -matrixB.txt原创 2017-06-23 01:03:38 · 1062 阅读 · 0 评论 -
LRU缓存和实现
LRU缓存是一种以LRU策略为缓存策略的缓存所谓的缓存策略,就是缓存满了以后又有新的数据加到缓存时,我们怎么替换清理缓存的方法LRU是last recently used的缩写,就是近期最少使用算法,依据程序的局部性原理,淘汰数据策略是距离当前最久没有被访问的数据应该被淘汰相关接口创建LRU缓存: – int LRUCacheCreate(int capacity,void **lruC原创 2017-05-03 21:56:22 · 711 阅读 · 0 评论 -
递归的理解
什么是递归递归又叫递回,指在函数的定义中使用函数自身的方法常用于解决的问题类型: – 该问题可以分解为规模更小但是形式相同的子问题 – 有退出递归的场景条件,就是不会出现死循环斐波那契数列#include<stdio.h>#include<stdlib.h>long long fabonacci(int n){ if(n == 0 || n == 1) {原创 2017-05-03 20:12:15 · 257 阅读 · 0 评论 -
leetcode--226. Invert Binary Tree
Invert a binary tree.4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 Trivia: This problem was inspired by this original tweet by Max Howell:原创 2016-04-22 23:40:55 · 301 阅读 · 0 评论 -
leetcode--104. Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the >longest path from the root node down to the farthest leaf >node. Subscribe to see which compan原创 2016-04-22 23:23:48 · 281 阅读 · 0 评论 -
leetcode--258. Add Digits
Given a non-negative integer num, repeatedly add all its >digits until the result has only one digit. For example: Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. >ince 2 has only原创 2016-04-22 22:58:47 · 304 阅读 · 0 评论 -
leetcode--292. Nim Game
You are playing the following Nim Game with your friend: >There is a heap of stones on the table, each time one of >you take turns to remove 1 to 3 stones. The one who >removes the last stone will be t原创 2016-04-22 22:42:40 · 397 阅读 · 0 评论 -
leetcode--344. Reverse String
Write a function that takes a string as input and returns >the string reversed. Example: Given s = “hello”, return “olleh”. char* reverseString(char* s) { char tempChar; int prePoi原创 2016-04-22 22:28:20 · 443 阅读 · 0 评论 -
Sunday算法学习
Sunday算法学习 判断字符串是否包含的算法,效率比KMP高,而且更加浅显易懂。 学习自yangfan876@126的博客。非常感谢~i,j两个指针分别从头开始匹配,当发现不匹配时,判断子串的后一位对应母串中的字符(上面的例子就是空格,k所在位置)在子串中是否存在(子串要从后向前匹配)。存在的话两位置对齐,再从头开始匹配,如果不存在就将子串整体后移,和母串k+1处的字符对齐,重新匹配,原创 2016-04-22 00:43:18 · 392 阅读 · 0 评论 -
b+树图文详解
转载自:伯乐专栏作者/玻璃猫,微信公众号 - 梦见 漫画:什么是b+树这一次我们来介绍 B+ 树。一个m阶的B树具有如下几个特征:1.根结点至少有两个子女。2.每个中间节点都包含k-1个元素和k个孩子,其中...转载 2019-06-06 21:20:09 · 496 阅读 · 0 评论