网上看了有些代码有些错误,这里重新更正了下
思想:循环数组有一边是有序的,首先先判断哪一边有序(通过将当前mid点与最左边节点比较),然后查看是否在有序边上
代码如下
#include
#include
using namespace std;
int Binary_Search(int *a,int low,int high,int value)
{
int mid=(low+high)...
分类:
其他好文 时间:
2014-09-12 19:11:56
阅读次数:
236
二分查找又称折半查找,优点是比较次数少,查找速度快;其缺点是要求待查表为有序表,且插入删除困难。因此,折半查找方法适用于不经常变动而查找频繁的有序列表。
该算法要求:
1、 必须采用顺序存储结构。
2、 必须按关键字大小有序排列。
该算法时间复杂度最坏为:O(logn)
注意点有mid、low、high...
分类:
编程语言 时间:
2014-09-12 17:17:23
阅读次数:
179
点击打开链接
有向图
把强联通分量缩点后得到一个DAG,然后DP。
#include
#include
#include
#include
#include
#include
using namespace std;
const int maxn = 1000 + 10;
vector G[maxn];
int dfn[maxn], low[maxn], sccno...
分类:
其他好文 时间:
2014-09-11 11:13:41
阅读次数:
159
快速排序:快速排序是对冒泡排序的一种改进。它的基本思想是,通过一趟排序将待排记录分割成独立的两部分,其中一部分记录的关键字均比另一部分记录的关键字小,则可分别对这两部分记录继续进行排序,以达到整个序列有序。
一趟快速排序的具体做法:
1、附设两个指针low和high,它们的初值分别为low和high,设枢轴记录的关键字为pivotkey。
2、首先从high所指位置起向前搜索找到第一...
分类:
其他好文 时间:
2014-09-11 09:39:51
阅读次数:
216
#include using namespace std;/*快速排序通过一趟排序,以轴点为界 分割为两部分:左部分 =length) //break; int i,key,j; if (low=key) //从高到低,直到找到第一个=length) //bre...
分类:
其他好文 时间:
2014-09-11 01:04:21
阅读次数:
228
1 public class Solution { 2 public boolean search(int[] A, int target) { 3 int low=0, high=A.length-1; 4 while (low=target) low=m...
分类:
其他好文 时间:
2014-09-09 23:02:39
阅读次数:
217
1 public class Solution { 2 public int search(int[] A, int target) { 3 int low=0, high=A.length-1; 4 5 while (lowA[mid] ...
分类:
其他好文 时间:
2014-09-09 21:30:09
阅读次数:
178
1.二分查找算法function two_find($arr,$low,$height,$k){ if($low<=$height){ $mid = intval(($low+$height)/2); if($arr[$mid]==$k){ r...
分类:
Web程序 时间:
2014-09-09 15:54:28
阅读次数:
197
public class QuickSort { public static void sort(int arr[],int low,int high){ int l=low; int h=high; int temp=arr[low]; ...
分类:
其他好文 时间:
2014-09-09 11:15:48
阅读次数:
241
import java.util.Scanner;public class Main { private static int count=0; public static void mergesort(int a[],int low,int high) { if(l...
分类:
编程语言 时间:
2014-09-09 10:39:58
阅读次数:
241