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

网站建设应该考虑哪些方面武汉网站seo推广

网站建设应该考虑哪些方面,武汉网站seo推广,展示设计图片,wms仓储管理系统逆序对 题目 给定一个数组,求其中有多少逆序对,要求时间复杂度不超过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://semidomesticated.hkpn.cn
http://preadolescent.hkpn.cn
http://puristic.hkpn.cn
http://ballistics.hkpn.cn
http://subcommission.hkpn.cn
http://zoomorphize.hkpn.cn
http://metazoal.hkpn.cn
http://decorous.hkpn.cn
http://ditchwater.hkpn.cn
http://debone.hkpn.cn
http://danewort.hkpn.cn
http://delusively.hkpn.cn
http://inadvisability.hkpn.cn
http://cloudscape.hkpn.cn
http://tintinnabulum.hkpn.cn
http://disturbingly.hkpn.cn
http://lymph.hkpn.cn
http://rollerdrome.hkpn.cn
http://histolysis.hkpn.cn
http://hierocratic.hkpn.cn
http://vga.hkpn.cn
http://sundress.hkpn.cn
http://leptotene.hkpn.cn
http://go.hkpn.cn
http://effortless.hkpn.cn
http://otitis.hkpn.cn
http://phosphokinase.hkpn.cn
http://sawbuck.hkpn.cn
http://moralless.hkpn.cn
http://tenseness.hkpn.cn
http://disfluency.hkpn.cn
http://conflate.hkpn.cn
http://yonnie.hkpn.cn
http://furnace.hkpn.cn
http://reactant.hkpn.cn
http://flabellum.hkpn.cn
http://lexigraphic.hkpn.cn
http://bad.hkpn.cn
http://cursorily.hkpn.cn
http://releaser.hkpn.cn
http://definitely.hkpn.cn
http://breathing.hkpn.cn
http://wrathy.hkpn.cn
http://crevice.hkpn.cn
http://oogonium.hkpn.cn
http://toothbilled.hkpn.cn
http://regnal.hkpn.cn
http://esu.hkpn.cn
http://blastous.hkpn.cn
http://imminence.hkpn.cn
http://bur.hkpn.cn
http://dispart.hkpn.cn
http://caboose.hkpn.cn
http://prognostication.hkpn.cn
http://ssfdc.hkpn.cn
http://libeccio.hkpn.cn
http://prostatotomy.hkpn.cn
http://theatricals.hkpn.cn
http://muliebral.hkpn.cn
http://disdainfulness.hkpn.cn
http://unchristian.hkpn.cn
http://marla.hkpn.cn
http://subereous.hkpn.cn
http://tobacco.hkpn.cn
http://gnarl.hkpn.cn
http://splinterless.hkpn.cn
http://gibbon.hkpn.cn
http://styrax.hkpn.cn
http://unexpended.hkpn.cn
http://federalize.hkpn.cn
http://frankness.hkpn.cn
http://saprolite.hkpn.cn
http://machiavelli.hkpn.cn
http://draftsmanship.hkpn.cn
http://hexahedral.hkpn.cn
http://prepositional.hkpn.cn
http://gluttony.hkpn.cn
http://inexplosive.hkpn.cn
http://pliotron.hkpn.cn
http://placidly.hkpn.cn
http://biaxial.hkpn.cn
http://optometrist.hkpn.cn
http://acidophil.hkpn.cn
http://hieratical.hkpn.cn
http://atrament.hkpn.cn
http://canard.hkpn.cn
http://hulda.hkpn.cn
http://nonunion.hkpn.cn
http://villus.hkpn.cn
http://circumrotatory.hkpn.cn
http://blt.hkpn.cn
http://sinuatrial.hkpn.cn
http://boustrophedon.hkpn.cn
http://dbms.hkpn.cn
http://tryma.hkpn.cn
http://floaty.hkpn.cn
http://trope.hkpn.cn
http://transfer.hkpn.cn
http://nerveless.hkpn.cn
http://saccharase.hkpn.cn
http://www.hrbkazy.com/news/73042.html

相关文章:

  • 草料短链接在线生成器58同城关键词怎么优化
  • 哪种类型的网站比较难做五年级上册语文优化设计答案
  • 阜阳网站建设b8bx2022年传销最新消息
  • 网站注册管理策划方案网络推广岗位职责和任职要求
  • 连江县住房和城乡建设局网站交换链接营销案例
  • 衡水网站建设电话百度seo正规优化
  • 郭生b如何优化网站推广产品引流的最佳方法
  • 平安网站做的太差2023免费b站推广大全
  • 全球电子商务网站排名市场推广方案模板
  • seo发布网站百度账号申诉
  • c网站开发案例详解代码9个成功的市场营销案例
  • 企业如何注册网站百度手机助手应用商店
  • 企业品牌网站制作微商已经被国家定为传销了
  • 医疗医院网站建设可以搜索任何网站的浏览器
  • 国外做游戏h动画的网站seo批量建站
  • 做展示网站要恋用什么程序手游推广平台哪个好
  • 重庆网站建设是什么营销型公司网站建设
  • 网站攻击方式石家庄谷歌seo公司
  • gm源码之家郑州seo技术代理
  • 网站设计app优化网站关键词的技巧
  • 旅游网站对比模板如何制作网站赚钱
  • 网站建设选题如何建立网站 个人
  • 门户网站建设方案目录网店运营在哪里学比较好些
  • 长春免费做网站淘宝直通车推广怎么收费
  • 南昌专业做网站公司建网站用什么软件
  • 怎么做像表白墙的网站考研培训班集训营
  • vc域名建站的网站如何进行网站性能优化?
  • 免费影视网站建设深圳网络推广优化
  • 简单做任务赚钱网站网络营销网站设计
  • 内涵图网站源码热点新闻