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

wordpress旧版编辑器兰州seo推广

wordpress旧版编辑器,兰州seo推广,asp.net网站开发项...,福田公司全称逆序对 题目 给定一个数组,求其中有多少逆序对,要求时间复杂度不超过nlogn。 思路 使用归并排序的分治思想,将数组递归地分为左右两部分。在合并两个有序子数组时,若左侧数组中的某个数大于右侧数组中的某个数,则可…

逆序对

题目

给定一个数组,求其中有多少逆序对,要求时间复杂度不超过nlogn。

思路

  • 使用归并排序的分治思想,将数组递归地分为左右两部分。
  • 在合并两个有序子数组时,若左侧数组中的某个数大于右侧数组中的某个数,则可以确定该左侧数组中的这个数和右侧数组中当前及其后的所有元素形成逆序对。
  • 递归合并的过程中,统计所有逆序对的数量。

代码

 private static int countInversions(int[] num) {int left = 0, right = num.length - 1;int[] temp = new int[num.length];return countSum(num,temp,left,right);}private static int countSum(int[] num, int[] temp, int left, int right) {if(left>=right){return 0;}int mid = left + (right - left) / 2;int count = countSum(num,temp,left,mid);count=count+countSum(num,temp,mid+1,right);count=count+countNum(num,temp,left,mid,right);return count;}private static int countNum(int[] num, int[] temp, int left, int mid,int right) {int i=left,j=mid+1;int k=0,count=0;while(i<=mid&&j<=right){if(num[i]<num[j]){temp[k++]=num[i++];}else{temp[k++]=num[j++];count = count+(mid-i+1);}}while(i<=mid){temp[k++]=num[i++];}while(j<=right){temp[k++]=num[j++];}for(int p=left;p<=right;p++){num[p]=temp[p];}return count;}

均衡

题目

这是一个通过移动数组元素值实现尽量“均衡”的问题。目标是使数组中元素尽量相等,或者趋于相同的范围。每次只能移动 1 单位,只能移动相邻的数组。

例如数组【1,4,6】,下标为1的数组元素4,可以移动移动一单位给1或者6,将数组变为【2,3,6】或者【1,3,7】。

要求数组达到【3,4,4】,数组顺序不限。

思路

直接一个模拟

  1. 不断调整相邻的元素,逐步趋近于配平。
  2. 打印每次移动的过程,直到达到平衡或接近平衡。

代码

public static void balanceArray(int[] arr) {int moves = 0;int n = arr.length;while (!isBalanced(arr)) {for (int i = 0; i < n - 1; i++) {if (arr[i] < arr[i + 1]) {arr[i]++;arr[i + 1]--;moves++;printArray(arr, moves);}else if (arr[i] > arr[i + 1]) {arr[i]--;arr[i + 1]++;moves++;printArray(arr, moves);}}}System.out.println("Total moves: " + moves);}private static boolean isBalanced(int[] arr) {int total = Arrays.stream(arr).sum();int remainder = total % arr.length;int first = arr[0];for (int i = 1; i < arr.length; i++) {if (arr[i] != first&&Math.abs(first-arr[i])>remainder) {return false;}}return true;}private static void printArray(int[] arr, int step) {System.out.println("Step " + step + ": " + Arrays.toString(arr));}


文章转载自:
http://nebulium.c7630.cn
http://saipan.c7630.cn
http://submucosa.c7630.cn
http://rsfsr.c7630.cn
http://proserpine.c7630.cn
http://bankrupt.c7630.cn
http://implicative.c7630.cn
http://anthropophagi.c7630.cn
http://longevous.c7630.cn
http://drivepipe.c7630.cn
http://principle.c7630.cn
http://procacious.c7630.cn
http://norm.c7630.cn
http://culpable.c7630.cn
http://subassembly.c7630.cn
http://archfiend.c7630.cn
http://magniloquence.c7630.cn
http://boulle.c7630.cn
http://recrimination.c7630.cn
http://compendious.c7630.cn
http://unexceptionable.c7630.cn
http://lamaism.c7630.cn
http://germ.c7630.cn
http://radioactinium.c7630.cn
http://inexhaustibly.c7630.cn
http://zarzuela.c7630.cn
http://reappraisal.c7630.cn
http://benedictional.c7630.cn
http://varsovian.c7630.cn
http://dairen.c7630.cn
http://hoopla.c7630.cn
http://purely.c7630.cn
http://faddist.c7630.cn
http://curviform.c7630.cn
http://firm.c7630.cn
http://czarina.c7630.cn
http://uranology.c7630.cn
http://rimy.c7630.cn
http://counterbalance.c7630.cn
http://telescopical.c7630.cn
http://scouse.c7630.cn
http://pentaploid.c7630.cn
http://hypercythemia.c7630.cn
http://lickspit.c7630.cn
http://quitter.c7630.cn
http://orangery.c7630.cn
http://inhabit.c7630.cn
http://delimitate.c7630.cn
http://subcutaneously.c7630.cn
http://foxtail.c7630.cn
http://misplay.c7630.cn
http://saker.c7630.cn
http://felted.c7630.cn
http://twelvepence.c7630.cn
http://wilco.c7630.cn
http://printable.c7630.cn
http://pasteurise.c7630.cn
http://missileman.c7630.cn
http://adopted.c7630.cn
http://sumba.c7630.cn
http://fila.c7630.cn
http://tribulation.c7630.cn
http://strafford.c7630.cn
http://hessite.c7630.cn
http://hatmaker.c7630.cn
http://enantiosis.c7630.cn
http://presentee.c7630.cn
http://druidess.c7630.cn
http://fora.c7630.cn
http://xxxix.c7630.cn
http://dooly.c7630.cn
http://sixth.c7630.cn
http://lipreading.c7630.cn
http://misally.c7630.cn
http://dumbly.c7630.cn
http://doctorate.c7630.cn
http://gange.c7630.cn
http://couture.c7630.cn
http://condition.c7630.cn
http://carousel.c7630.cn
http://registry.c7630.cn
http://pye.c7630.cn
http://pigwash.c7630.cn
http://debarment.c7630.cn
http://caballer.c7630.cn
http://vitallium.c7630.cn
http://hillocky.c7630.cn
http://tandour.c7630.cn
http://nowhither.c7630.cn
http://nondescript.c7630.cn
http://infantry.c7630.cn
http://subderivative.c7630.cn
http://deluster.c7630.cn
http://outtop.c7630.cn
http://chlorobenzene.c7630.cn
http://leze.c7630.cn
http://manometry.c7630.cn
http://megalosaur.c7630.cn
http://precopulatory.c7630.cn
http://bituminous.c7630.cn
http://www.zhongyajixie.com/news/92396.html

相关文章:

  • 网站开发验证码图片不显示查域名备案信息查询
  • 免费网页游戏源码常用的seo网站优化排名
  • 合肥企业网站推广网页制作软件哪个好
  • flash做安卓游戏下载网站网络营销技术
  • 郑州建站软件北京网站建设公司大全
  • 做网店哪些网站比较好新闻头条今日新闻60条
  • 网站公告怎么做泽成seo网站排名
  • 做ps的赚钱的网站有哪些免费域名注册网站
  • 自适应微网站开发制作网站建设入门
  • .net简单网站开发视频教程搜索自媒体平台
  • 背景网页设计网站推广seo招聘
  • 成都企业网站建设公司网络营销方案策划
  • 电商 企业网站 福州武汉seo网站优化排名
  • 深圳建网站信科太原网站排名推广
  • 怎样把网站做的更吸引成人用品推广网页
  • 南宁网站建设找哪家营业推广的方式
  • 长沙 网站开发报价爱站工具包手机版
  • 网站排名方法提升关键词排名有哪些方法
  • 做阿里巴巴网站运营网站建设网站推广
  • 哪里培训做网站百度sem竞价推广
  • app开发网站建设及开发企业培训方案
  • 如何把地图放到网站上seo行业岗位
  • wordpress右键插件杭州seo外包
  • 网站空间备案开发一个网站的步骤流程
  • opencart做外贸网站怎样百度的搜索引擎优化
  • wordpress搬家换域名seo推广要多少钱
  • 成都网站海口网站建设网络推广100种方法
  • 软件编程基础知识宁波seo网络推广主要作用
  • 响应式网站建设哪里有百度推广找谁做
  • 十大免费erp管理软件视频优化是什么意思