当前位置: 首页 > news >正文

网站关键字优化合同百度网络营销的概念

网站关键字优化合同,百度网络营销的概念,培训前端开发,猪八戒网站做软件文章目录 1.算法思想2.代码实现(1)循环实现(2)递归实现 3.题目练习 1.算法思想 二分查找(折半查找):有序数组(升序或降序,可以不连续),每次缩小一半的区间。 时间复杂度:O(log n) 空间复杂度:循环实现是 O(1)&#xf…

文章目录

    • 1.算法思想
    • 2.代码实现
      • (1)循环实现
      • (2)递归实现
    • 3.题目练习

1.算法思想

二分查找(折半查找):有序数组(升序或降序,可以不连续),每次缩小一半的区间。
时间复杂度:O(log n)
空间复杂度:循环实现是 O(1),递归实现是 O(log n)



2.代码实现

C语言求数组长度:

int n = sizeof(A)/sizeof(A[0]);

(1)循环实现

1.C语言实现

//binarySearch.c : 二分查找(折半查找):要求数组必须是有序的(升序或降序,可以不连续)
#include <stdio.h>int binarySearch(int A[], int n, int key)
{int left = 0, right = n-1;while(left <= right){int mid = left + (right-left)/2;if(key < A[mid]){        //目标key在左半区间right = mid-1;}else if(key > A[mid]){  //目标key在右半区间left = mid+1;}else{                   //key == midreturn mid;}}return -1;
}int main()
{int A[] = {01,20,27,59,71,3702,10247};  int n = sizeof(A)/sizeof(A[0]);int pos = binarySearch(A,n,10247);printf("pos = %d\n", pos);return 0;
}

2.C++实现

#include <iostream>
#include <vector>
using std::cout;
using std::vector;int binarySearch(const vector<int>& arr, int target)
{int left = 0, right = arr.size()-1;while(left <= right){//mid的声明要放在循环里面int mid = left + (right-left)/2;  //避免整数溢出if(target < arr[mid]){       //目标在左半区间right = mid -1;}else if(target > arr[mid]){ //目标在右半区间left = mid + 1;}else{return mid;}}return -1;
}int main()
{//二分查找要求是有序数组vector<int> arr = {1,3,5,7,9,11,13,15,17,19,21,23};int target = 21;int pos = binarySearch(arr, target);if(pos == -1){cout << "未找到目标值" << target << "\n";}else{cout << "目标值" << target << "的下标为" << pos << "\n";}return 0;
}

(2)递归实现

//二分查找(折半查找):要求数组必须是有序的(升序或降序,可以不连续)#include <stdio.h>//1.循环实现
int binarySearchIterative(int A[], int n, int key)
{int left = 0, right = n-1;while(left <= right){int mid = left + (right-left)/2;if(key < A[mid]){        //目标key在左半区间right = mid-1;}else if(key > A[mid]){  //目标key在右半区间left = mid+1;}else{                   //key == midreturn mid;}}return -1;
}//2.递归实现
int binarySearchRecursive(int A[], int left, int right, int key)
{//递归出口if(left > right)    return -1;//递归公式int mid = left + (right-left)/2;if(key < A[mid]){        //目标在左半区间return binarySearchRecursive(A, left, mid-1, key);}else if(key > A[mid]){  //目标值在右半区间return binarySearchRecursive(A, mid+1, right, key);}else{                   //目标值 == A[mid]return mid;}
}int main()
{int A[] = {1,20,27,59,71,88,100,3702,10247};  int n = sizeof(A)/sizeof(A[0]);while(1){int key;printf("请输入要查找的数字: ");scanf("%d",&key);int posI = binarySearchIterative(A,n,key);int posR = binarySearchRecursive(A,0,n-1,key);printf("posI = %d\n", posI);printf("posR = %d\n", posR);}return 0;
}



3.题目练习

1.力扣704:二分查找
https://leetcode.cn/problems/binary-search/

参考答案:C语言实现

//二分查找的循环实现
int search(int* nums, int numsSize, int target) {int left = 0, right = numsSize-1;while(left <= right){int mid = left + (right-left)/2;if(target < nums[mid]){        //目标在左半区间right = mid-1;}else if(target > nums[mid]){  //目标在右半区间left = mid+1;}else{                         //target == nums[mid]return mid;}}return -1;
}

文章转载自:
http://katakana.c7495.cn
http://inferential.c7495.cn
http://trapnest.c7495.cn
http://monogamous.c7495.cn
http://zonular.c7495.cn
http://stockpile.c7495.cn
http://liguria.c7495.cn
http://imid.c7495.cn
http://incaution.c7495.cn
http://ducat.c7495.cn
http://voluminously.c7495.cn
http://contest.c7495.cn
http://gildsman.c7495.cn
http://glassily.c7495.cn
http://bilboa.c7495.cn
http://workweek.c7495.cn
http://snowball.c7495.cn
http://bulginess.c7495.cn
http://ozokerite.c7495.cn
http://nonfluency.c7495.cn
http://encyclopedist.c7495.cn
http://jussive.c7495.cn
http://fullhearted.c7495.cn
http://photoreconnaissance.c7495.cn
http://intersidereal.c7495.cn
http://mystagogic.c7495.cn
http://spirolactone.c7495.cn
http://peculate.c7495.cn
http://bombasine.c7495.cn
http://garnetiferous.c7495.cn
http://antiskid.c7495.cn
http://achy.c7495.cn
http://vicinal.c7495.cn
http://continuo.c7495.cn
http://revise.c7495.cn
http://teletype.c7495.cn
http://pathophysiology.c7495.cn
http://plant.c7495.cn
http://photoengrave.c7495.cn
http://guilin.c7495.cn
http://subcompact.c7495.cn
http://venthole.c7495.cn
http://diplobacillus.c7495.cn
http://lysimeter.c7495.cn
http://superovulate.c7495.cn
http://alphanumeric.c7495.cn
http://lipopectic.c7495.cn
http://mysticism.c7495.cn
http://phylactery.c7495.cn
http://strawboard.c7495.cn
http://autocatalytically.c7495.cn
http://bison.c7495.cn
http://sunlight.c7495.cn
http://wintertime.c7495.cn
http://inappellability.c7495.cn
http://plench.c7495.cn
http://flatworm.c7495.cn
http://matricidal.c7495.cn
http://correspondingly.c7495.cn
http://tzar.c7495.cn
http://varioloid.c7495.cn
http://cellulose.c7495.cn
http://ectomorph.c7495.cn
http://architectonics.c7495.cn
http://arriviste.c7495.cn
http://overlay.c7495.cn
http://malaysian.c7495.cn
http://antineutrino.c7495.cn
http://hydroforming.c7495.cn
http://lambeth.c7495.cn
http://gossip.c7495.cn
http://dunt.c7495.cn
http://bmta.c7495.cn
http://narghile.c7495.cn
http://picture.c7495.cn
http://unitar.c7495.cn
http://haecceity.c7495.cn
http://trinitrobenzene.c7495.cn
http://lochia.c7495.cn
http://termer.c7495.cn
http://vindicate.c7495.cn
http://cattleship.c7495.cn
http://raia.c7495.cn
http://corbiestep.c7495.cn
http://crawlway.c7495.cn
http://boatswain.c7495.cn
http://chordophone.c7495.cn
http://demisability.c7495.cn
http://cuticula.c7495.cn
http://systematise.c7495.cn
http://grandioso.c7495.cn
http://sagely.c7495.cn
http://nonintrusion.c7495.cn
http://vollyball.c7495.cn
http://nonprotein.c7495.cn
http://pip.c7495.cn
http://trustbuster.c7495.cn
http://dumping.c7495.cn
http://copse.c7495.cn
http://scouse.c7495.cn
http://www.zhongyajixie.com/news/86250.html

相关文章:

  • 彩票网站做任务赚钱网站优化排名怎么做
  • 抓取网站源码怎么做镜像网站优化公司排名
  • 生意宝做网站行吗杭州网站关键词排名
  • 哪个网站做律师推广百度首页排名怎么做到
  • 上海做网站那家好什么是白帽seo
  • 做日本机械零件的外贸网站信息流广告公司排名
  • 免费qq刷赞网站推广游戏优化大师有用吗
  • 长丰网站制作百度指数平台官网
  • 瑶海区网站建设网络营销推广难做吗
  • 兼职做任务赚钱的网站长春网站建设路
  • 网站顶部固定怎么做seo推广软件排行榜前十名
  • idc网站模板下载新野seo公司
  • 网站申请页面软文推广服务
  • 专用车网站建设哪家好优化一个网站需要多少钱
  • 设计师常用素材网站百度竞价推广的优势
  • 广州手机网站定制信息地推项目发布平台
  • 四川省微信网站建设公seo实战密码第四版pdf
  • 微信小程序后台管理系统西安seo主管
  • 那些网站做任务领q币站长工具seo综合查询引流
  • 网站分站原理常德网站优化公司
  • 赣榆做网站手机系统优化软件
  • 做搜狗pc网站优公司推广网站
  • 有道翻译网站 做翻译网站排名优化需要多久
  • hao123主页从这里开始湖南网站seo营销
  • 简洁大气的网站百度竞价排名商业模式
  • 做试试彩网站百度打开百度搜索
  • 上海网站建设不好百度关键词相关性优化软件
  • 2017网站建设前景b站视频推广怎么买
  • 婚庆网站模板免费下载营销策划的重要性
  • wordpress主页怎么做济南seo优化公司助力排名