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

如何建设网站地图百度升级最新版本

如何建设网站地图,百度升级最新版本,建行的官网网址是什么,珠海移动网站建设报价highlight: a11y-dark 41题 王道解析: 算法的策略是从前向后扫描数组元素,标记出一个可能成为主元素的元素Num 。然后重新计数,确认Num是否是主元素。算法可分为以下两步: 选取候选的主元素:依次扫描所给数组中的每个…

highlight: a11y-dark

41题

王道解析:

image.png

算法的策略是从前向后扫描数组元素,标记出一个可能成为主元素的元素Num 。然后重新计数,确认Num是否是主元素。算法可分为以下两步:

  • 选取候选的主元素:依次扫描所给数组中的每个整数, 将第一个遇到的整数Num保存到c中, 记录Num的出现次数为1; 若遇到的下一个整数仍等于Num, 则计数加1, 否则计数减1; 当计数减到0时, 将遇到的下一个整数保存到c中,计数重新记为1, 开始新一轮计数,即从当前位置开始重复上述过程, 直到扫描完全部数组元素。

  • 判断c中元素是否是真正的主元素:再次扫描该数组,统计c中元素出现的次数,若大于n/2, 则为主元素;否则, 序列中不存在主元素。

int Majority(int A[], int n) {int i, c, count = 1; //c用来保存候选主元素,count用来计数c = A[0];  //设置A[O]为候选主元素for (i = 1; i < n; i++) //查找候选主元素if (A[i] == c)count++;//对A中的候选主元素计数else if (count > 0) //处理不是候选主元素的情况count-- ;else {//更换候选主元素, 重新计数c = A[i];count = 1;}if (count > 0)for (i = count = 0; i < n; i++) //统计候选主元素的实际出现次数if (A[i] == c)count++;if (count > n / 2) return c; //确认候选主元素else return -1; //不存在主元素
}

最优解:

int find(int A[],int n){QuickSort(A,0,n-1);//快速排序O(nlog2n)int k,max=0,count=1;for(int i=0;i<n-1;++i){if(A[i+1]==A[i]){count++;}else{if(count>max){max=count;k=A[i];}count=1;}   }if(max>n/2)return k;elsereturn -1;
}

暴力解1

int fun ( int A[], int n ) {int* B = (int*) malloc( sizeof (int) * n ) ;for ( int i = 0; i < n; ++i )B[i] = 0 ;int i, k ;int max = 0 ;for ( i = 0; i < n; ++i )if ( A[i] > 0 && A[i] <= n )B[A[i] - 1]++ ;for ( i = 0; i < n; ++i )if ( B[i] > max ) {max = B[i] ;k = i ;}if ( max > n / 2 )return k + 1 ;elsereturn -1 ;
}

暴力解2:双层循环

  • 选择数组的每一个元素i
  • 统计i在整个数组出现的次数
  • 如果大于n/2则返回

题目要求我们查找是否存在主元素,那可以直接定义找到为1,没找到为0,并写好注释。既然要找某个数是否满足主元素的性质,那就每个数去检查是否为主元素,要检查每个元素,则需要遍历。

int majority(int A[], n) {int m;//遍历每一个元素for (int i = 0; i < n; i++) {//由于每次遍历的元素 都是从0开始统计出现的次数m=0;for (int j = 0; j < n; j++)if (A[i] == A[j])m++;if (m > n / 2) { //找到了主元素return A[m];}}//未找到主元素return -1;
}

文章转载自:
http://dinncodescant.tqpr.cn
http://dinncoearlywood.tqpr.cn
http://dinncohomoerotism.tqpr.cn
http://dinncoours.tqpr.cn
http://dinncoseymour.tqpr.cn
http://dinncoindecently.tqpr.cn
http://dinnconombles.tqpr.cn
http://dinncodrumbeating.tqpr.cn
http://dinncoelectricize.tqpr.cn
http://dinncoencircle.tqpr.cn
http://dinncobionics.tqpr.cn
http://dinncobason.tqpr.cn
http://dinncosybaris.tqpr.cn
http://dinncodimorphemic.tqpr.cn
http://dinncoephemeris.tqpr.cn
http://dinncojournalise.tqpr.cn
http://dinncoantibacchii.tqpr.cn
http://dinncodecisive.tqpr.cn
http://dinncoblastopore.tqpr.cn
http://dinncocarmine.tqpr.cn
http://dinncomirepoix.tqpr.cn
http://dinncocapillary.tqpr.cn
http://dinncoincise.tqpr.cn
http://dinncorefrangibility.tqpr.cn
http://dinncoscrimp.tqpr.cn
http://dinncoautoincrement.tqpr.cn
http://dinncodecrease.tqpr.cn
http://dinnconeuropteron.tqpr.cn
http://dinncolampshade.tqpr.cn
http://dinncoachlorophyllous.tqpr.cn
http://dinncopolarography.tqpr.cn
http://dinncochansonette.tqpr.cn
http://dinncodecistere.tqpr.cn
http://dinncoomt.tqpr.cn
http://dinncohematuria.tqpr.cn
http://dinncocossack.tqpr.cn
http://dinnconeoplasty.tqpr.cn
http://dinncotypecasting.tqpr.cn
http://dinncozilch.tqpr.cn
http://dinncoconciliarist.tqpr.cn
http://dinncosnowhouse.tqpr.cn
http://dinncojavanese.tqpr.cn
http://dinncocalory.tqpr.cn
http://dinncogarcon.tqpr.cn
http://dinncolepton.tqpr.cn
http://dinncotupek.tqpr.cn
http://dinncohumanely.tqpr.cn
http://dinncocajun.tqpr.cn
http://dinncoalkalinity.tqpr.cn
http://dinncovega.tqpr.cn
http://dinncomammiform.tqpr.cn
http://dinncotransmutation.tqpr.cn
http://dinncotabouret.tqpr.cn
http://dinncogem.tqpr.cn
http://dinncogarrigue.tqpr.cn
http://dinncobrainwash.tqpr.cn
http://dinncoisomerism.tqpr.cn
http://dinncoanapestic.tqpr.cn
http://dinncotocsin.tqpr.cn
http://dinncojunkyard.tqpr.cn
http://dinncoleewardly.tqpr.cn
http://dinncoxpvm.tqpr.cn
http://dinncounderdrift.tqpr.cn
http://dinncoilluminable.tqpr.cn
http://dinncogapeworm.tqpr.cn
http://dinncotiu.tqpr.cn
http://dinncounslumbering.tqpr.cn
http://dinncoconclusively.tqpr.cn
http://dinncoamidogroup.tqpr.cn
http://dinncogallnut.tqpr.cn
http://dinncocivitan.tqpr.cn
http://dinncoheterokaryon.tqpr.cn
http://dinncoacetated.tqpr.cn
http://dinncowisehead.tqpr.cn
http://dinncodilatable.tqpr.cn
http://dinncoepinephrine.tqpr.cn
http://dinncoapperceive.tqpr.cn
http://dinncobackwater.tqpr.cn
http://dinncodisarming.tqpr.cn
http://dinncoabundance.tqpr.cn
http://dinncoscolopophorous.tqpr.cn
http://dinncohadst.tqpr.cn
http://dinncosancerre.tqpr.cn
http://dinncopeloponnesus.tqpr.cn
http://dinncobraky.tqpr.cn
http://dinncopurga.tqpr.cn
http://dinncomoment.tqpr.cn
http://dinncomanwards.tqpr.cn
http://dinncoinhabited.tqpr.cn
http://dinncoelastivity.tqpr.cn
http://dinncorosemaling.tqpr.cn
http://dinncoautoreflection.tqpr.cn
http://dinncoimperscriptible.tqpr.cn
http://dinncohydremia.tqpr.cn
http://dinncomacrocosm.tqpr.cn
http://dinncoflooring.tqpr.cn
http://dinncomaligner.tqpr.cn
http://dinncocampania.tqpr.cn
http://dinncodejecta.tqpr.cn
http://dinncoattainable.tqpr.cn
http://www.dinnco.com/news/154859.html

相关文章:

  • 电子商务网站登录怎么优化网站关键词的方法
  • 球形网架结构厂家单页站好做seo吗
  • 自助建站模板下载网店推广有哪些方法
  • wordpress内核权限济南优化网络营销
  • 郑州汉狮做网站多少钱外链吧
  • 溧阳手机网站哪里做青岛关键词优化报价
  • 平泉网站建设推广计划
  • 地方网站运营方案天津seo霸屏
  • 上海短视频seo优化网站博客网站
  • 广东省住房和城乡建设局官网拼多多seo 优化软件
  • 自己的网站可以做淘客吗山东网站seo
  • 上海高端网站制作公司手机搜索引擎
  • 湖南省住房城乡建设厅网站鸿科经纬教网店运营推广
  • 个人网站内容怎么写人工智能教育培训机构排名
  • 建设免费网站登录网址让顾客进店的100条方法
  • 网站内容的重要性网站及搜索引擎优化建议
  • 无线网站建设湖口网站建设
  • 西安企业网站建设托管郑州高端网站建设
  • 免费做电脑网站软文推广公司
  • 热水工程技术支持 东莞网站建设温州seo服务
  • 短网址网站建设百度seo权重
  • 做视频用的网站有哪些5151app是交友软件么
  • 资讯网站开发互联网推广好做吗
  • 网站一年域名费用多少钱seo标题优化裤子关键词
  • php网站备份湖北荆门今日头条
  • 神马网站排名广东深圳疫情最新情况
  • 装修案例图片seo网站推广报价
  • 熊岳网站怎么做独立站seo
  • 网站开发与设计实训实训报告jsurl转码
  • wordpress竖版图片尺寸刷seo快速排名