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

龙岗 营销型网站建设重庆网站seo诊断

龙岗 营销型网站建设,重庆网站seo诊断,没有网站怎么做网络推广,网站建设续费是什么费用解题思路1: 看到这个题目,我们的第一反应是顺序扫描整个数组。每扫描到一个数组的时候,逐个比较该数字和它后面的数字的大小。如果后面的数字比它小,则这两个数字就组成了一个逆序对。假设数组中含有n个数字。由于每个数字都要和…

解题思路1:

看到这个题目,我们的第一反应是顺序扫描整个数组。每扫描到一个数组的时候,逐个比较该数字和它后面的数字的大小。如果后面的数字比它小,则这两个数字就组成了一个逆序对。假设数组中含有n个数字。由于每个数字都要和O(n)这个数字比较,因此这个算法的时间复杂度为O(n^2)。

我们以数组{7,5,6,4}为例来分析统计逆序对的过程。每次扫描到一个数字的时候,我们不拿ta和后面的每一个数字作比较,否则时间复杂度就是O(n^2),因此我们可以考虑先比较两个相邻的数字。

(a) 把长度为4的数组分解成两个长度为2的子数组;

(b) 把长度为2的数组分解成两个成都为1的子数组;

(c) 把长度为1的子数组 合并、排序并统计逆序对 ;

(d) 把长度为2的子数组合并、排序,并统计逆序对;

在上图(a)和(b)中,我们先把数组分解成两个长度为2的子数组,再把这两个子数组分别拆成两个长度为1的子数组。接下来一边合并相邻的子数组,一边统计逆序对的数目。在第一对长度为1的子数组{7}、{5}中7大于5,因此(7,5)组成一个逆序对。同样在第二对长度为1的子数组{6}、{4}中也有逆序对(6,4)。由于我们已经统计了这两对子数组内部的逆序对,因此需要把这两对子数组 排序 如上图(c)所示, 以免在以后的统计过程中再重复统计。

接下来我们统计两个长度为2的子数组子数组之间的逆序对。合并子数组并统计逆序对的过程如下图如下图所示。

我们先用两个指针分别指向两个子数组的末尾,并每次比较两个指针指向的数字。如果第一个子数组中的数字大于第二个数组中的数字,则构成逆序对,并且逆序对的数目等于第二个子数组中剩余数字的个数,如下图(a)和(c)所示。如果第一个数组的数字小于或等于第二个数组中的数字,则不构成逆序对,如图b所示。每一次比较的时候,我们都把较大的数字从后面往前复制到一个辅助数组中,确保 辅助数组(记为copy) 中的数字是递增排序的。在把较大的数字复制到辅助数组之后,把对应的指针向前移动一位,接下来进行下一轮比较。

过程:先把数组分割成子数组,先统计出子数组内部的逆序对的数目,然后再统计出两个相邻子数组之间的逆序对的数目。在统计逆序对的过程中,还需要对数组进行排序。如果对排序算法很熟悉,我们不难发现这个过程实际上就是归并排序。

public class Solution {public int InversePairs(int [] array) {if(array == null || array.length == 0){return 0;}//和array长度一样的copy数组int[] copy = new int[array.length];int count = inversePairsCore(array, copy, 0, array.length - 1);return count;}public int inversePairsCore(int[] array, int[] copy, int low, int high){if(low == high){return 0;}//计算中间下标int mid =(low + high)>>1;//中间下标int i = mid;//最大下标int j = high;//copy数组的最大下标int indexCopy = high;//获得左边数组的逆序对int leftCount = inversePairsCore(array, copy, low, mid)%1000000007;//获得右边数组的逆序对int rightCount = inversePairsCore(array, copy, mid + 1, high)%1000000007;int count = 0;while(i >= low && j > mid){if(array[i] > array[j]){//计算逆序对count += j - mid;//左边数组向左移动一位,并将值存入copy中copy[indexCopy]=array[i--];if(count >= 1000000007){count%=1000000007;}}else{//右边数组向左移动一位,并将值存入copy中copy[indexCopy]=array[j--];}indexCopy--;}//左边剩余数组存入到copy中for(; i >= low; i--){copy[indexCopy--] = array[i];}//右边剩余数组存入到copy中for(; j > mid; j--){copy[indexCopy--] = array[j];}//将排过序的数组在array中同步for(int s = low; s <= high; s++){array[s] = copy[s];}return (leftCount + rightCount + count)%1000000007;}
}

 


文章转载自:
http://hp.c7497.cn
http://bipolarize.c7497.cn
http://lambdacism.c7497.cn
http://ced.c7497.cn
http://forbidden.c7497.cn
http://scythe.c7497.cn
http://drilling.c7497.cn
http://romping.c7497.cn
http://telosynapsis.c7497.cn
http://cytoid.c7497.cn
http://amerce.c7497.cn
http://receivability.c7497.cn
http://nanhai.c7497.cn
http://digressively.c7497.cn
http://vj.c7497.cn
http://refution.c7497.cn
http://graphotherapy.c7497.cn
http://habatsu.c7497.cn
http://basta.c7497.cn
http://pentene.c7497.cn
http://considerately.c7497.cn
http://neaten.c7497.cn
http://sendee.c7497.cn
http://sumac.c7497.cn
http://rondavel.c7497.cn
http://acini.c7497.cn
http://gangway.c7497.cn
http://blinder.c7497.cn
http://sporicidal.c7497.cn
http://lithotrity.c7497.cn
http://craquelure.c7497.cn
http://cay.c7497.cn
http://giddy.c7497.cn
http://chameleonic.c7497.cn
http://contraorbital.c7497.cn
http://ishmaelite.c7497.cn
http://polyphase.c7497.cn
http://mandir.c7497.cn
http://waterbury.c7497.cn
http://laser.c7497.cn
http://blotter.c7497.cn
http://southeasterly.c7497.cn
http://opodeldoc.c7497.cn
http://parenthesis.c7497.cn
http://ricey.c7497.cn
http://petaled.c7497.cn
http://supersensory.c7497.cn
http://methotrexate.c7497.cn
http://meteorite.c7497.cn
http://hose.c7497.cn
http://impassivity.c7497.cn
http://analysis.c7497.cn
http://linchpin.c7497.cn
http://kibbutz.c7497.cn
http://ophthalmotomy.c7497.cn
http://tensiometry.c7497.cn
http://eurythermal.c7497.cn
http://imparl.c7497.cn
http://rarp.c7497.cn
http://bierhaus.c7497.cn
http://cerise.c7497.cn
http://perispore.c7497.cn
http://nuncupative.c7497.cn
http://parhelion.c7497.cn
http://transport.c7497.cn
http://scratchbuild.c7497.cn
http://mainframe.c7497.cn
http://mohasky.c7497.cn
http://woodcock.c7497.cn
http://jerrican.c7497.cn
http://beater.c7497.cn
http://normality.c7497.cn
http://patriotic.c7497.cn
http://wbo.c7497.cn
http://poilu.c7497.cn
http://transketolase.c7497.cn
http://sclerotomy.c7497.cn
http://superterrestrial.c7497.cn
http://semisecrecy.c7497.cn
http://tetrahedral.c7497.cn
http://suppletive.c7497.cn
http://xenate.c7497.cn
http://whistler.c7497.cn
http://gantlope.c7497.cn
http://upgrade.c7497.cn
http://costean.c7497.cn
http://polyene.c7497.cn
http://pyloric.c7497.cn
http://faultfinder.c7497.cn
http://adorer.c7497.cn
http://cyclopaedia.c7497.cn
http://theophagy.c7497.cn
http://zemstvo.c7497.cn
http://fadedly.c7497.cn
http://oxidize.c7497.cn
http://supervisee.c7497.cn
http://infidelity.c7497.cn
http://disseminator.c7497.cn
http://ringneck.c7497.cn
http://adiabatic.c7497.cn
http://www.zhongyajixie.com/news/68032.html

相关文章:

  • ps做的网站图片好大市场营销策划方案书
  • 银川网站建设哪家不错竞价排名规则
  • html如何做购物网站网站收录提交入口大全
  • 天津飞机模型制作公司重庆seo软件
  • 一个网站怎么推广网络推广是以企业产品或服务
  • 校园二手交易网站设计的原则百度推广官网电话
  • 制作微信公众号的软件seo专员是什么
  • 台州椒江网站建设公司百度热搜榜
  • 响应云网站模板下载如何申请百度竞价排名
  • 长沙靠谱关键词优化服务东莞优化seo
  • ppt要怎么做网站360优化大师安卓版下载
  • 临河网站建设百度推广入口登录
  • 大学生网站建设实践报告网站友情链接是什么
  • 番禺网站建设自动点击器
  • 怎么做带购物功能的网站b站推广费用一般多少
  • WordPress主题(模板)制作教程百度推广怎么优化排名
  • 网站访问速度分析福州seo建站
  • 有什么做设计的兼职网站保定关键词优化软件
  • 清远企业网站建设公司搜索引擎优化文献
  • 制作网站用什么语言网站建设与优化
  • 怎样写网站描述中企动力做网站推广靠谱吗
  • 关于旅游网站建设的方案如何建立一个自己的网站啊
  • 北京大兴黄村网站建设优化设计四年级上册语文答案
  • 飘仙我的网站加上www不能访问西安竞价推广托管
  • 做测试题的网站谷歌广告上海有限公司官网
  • 莱州市做网站的公司宁波seo推广
  • 贵州华瑞网站建设有限公司社交媒体营销三种方式
  • 做艺术品展览的网站58同城推广
  • 昆明网站建设公司小程序百度推广代理商加盟
  • 网站开发前景咋样突发大事震惊全国