Peterson's algorithm (AKA Peterson's solution) is a concurrent
programming algorithm for mutual
exclusion that allows two processes to share a single-use resource without conflict, using only shar...
分类:
编程语言 时间:
2014-06-25 19:38:19
阅读次数:
748
Given an array of integers, every element appears twice except for one. Find that single one.
Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using e...
分类:
其他好文 时间:
2014-06-24 23:30:08
阅读次数:
278
%%% Fragment
%%% 对原图做四个方向的平移,然后对平移的结果取平均
%%% 碎片效果
clc;
clear all;
addpath('E:\PhotoShop Algortihm\Image Processing\PS Algorithm');
Image=imread('4.jpg');
Image=double(Image)/255;...
分类:
其他好文 时间:
2014-06-24 21:06:24
阅读次数:
226
heapq模块实现了python中的堆排序,并提供了有关方法。让用Python实现排序算法有了简单快捷的方式。
heapq的官方文档和源码:8.4.heapq-Heap queue algorithm
下面通过举例的方式说明heapq的应用方法
实现堆排序
#! /usr/bin/evn python
#coding:utf-8
from heapq import *
def ...
分类:
编程语言 时间:
2014-06-24 18:47:47
阅读次数:
403
Given a sorted array of integers, find the starting and ending position of a given target value.
Your algorithm's runtime complexity must be in the order of O(log n).
If the target is not found ...
分类:
其他好文 时间:
2014-06-22 21:47:15
阅读次数:
269
最近学习了c++primer中的第11章的泛型算法,这一章的基础是c++中的容器,但是泛型算法是独立于特定的容器的,这样的算法不会改变容器的大小,这样保证了不管是哪种类型的容器都可以同时调用同一种算法来实现操作。
首先介绍下这些常用的算法的头文件,比较常用的是algorithm,numeric和iterator,最先遇到的函数是find()函数,需要三个参数,前两个是一般的算法函数都需要的,是一...
分类:
编程语言 时间:
2014-06-22 16:57:43
阅读次数:
277
无向图最小生成树的Prim算法,在实现上方法各异。本文演示了用Python是实现的方法,特别是应用了Python有的一个heapq排序方法,让代码更简洁。...
分类:
其他好文 时间:
2014-06-22 16:11:00
阅读次数:
176
算法(Algorithm) 是利用计算机解决问题的处理步骤。 算法是古老的智慧。如《孙子兵法》,是打胜仗的算法。 算法是古老智慧的结晶,是程序的范本。 学习算法才能编写出高质量的程序。 懂得了算法,游戏水平会更高。 比如下棋,如果懂得棋谱,就不需要每次考虑“寻找最好的一步棋”,按照棋谱 就可以走出最...
分类:
其他好文 时间:
2014-06-22 10:57:40
阅读次数:
175
克鲁斯卡尔算法(Kruskal's algorithm)是两个经典的最小生成树算法的较为简单理解的一个。这里面充分体现了贪心算法的精髓。大致的流程能够用一个图来表示。这里的图的选择借用了Wikipedia上的那个。很清晰且直观。首先第一步,我们有一张图,有若干点和边例如以下图所看到的:第一步我们要做...
分类:
其他好文 时间:
2014-06-22 09:46:37
阅读次数:
194
首先讲stream流类
头文件#include
其功能是进行不同类型之间的转换,跟C语言 fscanf 和 fprintf 作用是相同的,但是比C语言的更简便更好用。
用法很简单
#include
#include
#include
int main()
{
std::stringstream stream;
std::string result;
in...
分类:
编程语言 时间:
2014-06-22 09:05:45
阅读次数:
295