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

中科院网站做的好的院所如何进行网站性能优化

中科院网站做的好的院所,如何进行网站性能优化,九江网站制作,辽宁移动网站Problem: 830. 单调栈 文章目录 思路解题方法复杂度Code 思路 这是一个单调栈的问题。单调栈是一种特殊的栈结构,它的特点是栈中的元素保持单调性。在这个问题中,我们需要找到每个元素左边第一个比它小的元素,这就需要使用到单调递增栈。 我们…

Problem: 830. 单调栈

文章目录

  • 思路
  • 解题方法
  • 复杂度
  • Code

思路

这是一个单调栈的问题。单调栈是一种特殊的栈结构,它的特点是栈中的元素保持单调性。在这个问题中,我们需要找到每个元素左边第一个比它小的元素,这就需要使用到单调递增栈。

我们从左到右遍历数组,对于每个元素,如果栈为空或者当前元素大于栈顶元素,就将当前元素入栈;否则,就将栈顶元素出栈,直到栈为空或者找到一个栈顶元素小于当前元素,然后将当前元素入栈。这样,栈中的元素就始终保持了单调递增的性质。

在这个过程中,每当我们要将一个元素出栈时,就找到了这个元素左边第一个比它小的元素(就是当前的栈顶元素)。我们可以在这个时候记录下这个信息。

解题方法

我们使用一个栈和一个二维数组。栈用来存储元素的索引,二维数组用来存储每个元素左边第一个比它小的元素的索引和右边第一个比它小的元素的索引。

在遍历数组的过程中,我们使用一个指针r来表示栈顶。每当我们要将一个元素i入栈时,如果栈不为空并且栈顶元素大于等于当前元素,就将栈顶元素出栈,并记录下这个元素左边第一个比它小的元素的索引(就是当前的栈顶元素)和右边第一个比它小的元素的索引(就是当前的元素i)。然后将元素i入栈。

在遍历完数组后,栈中可能还有元素。这些元素右边没有比它小的元素,所以我们将这些元素出栈,并记录下这个元素左边第一个比它小的元素的索引(就是当前的栈顶元素)。

最后,我们需要修正一下结果。因为可能存在连续的相同的元素,这些元素右边第一个比它小的元素应该是相同的。所以我们从右到左遍历数组,如果一个元素和它右边的元素相同,就将它的右边第一个比它小的元素的索引更新为它右边的元素的右边第一个比它小的元素的索引。

复杂度

时间复杂度:

O ( n ) O(n) O(n),我们只遍历了一次数组。

空间复杂度:

O ( n ) O(n) O(n),我们使用了一个栈和一个二维数组来存储信息。

Code

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;public class Main {static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));static StreamTokenizer sr = new StreamTokenizer(in);static int MAXN = (int) (1e5 + 10);static int n, r;static int[] arr = new int[MAXN];static int[][] ans = new int[MAXN][2];static int[] stack = new int[MAXN];public static void main(String[] args) throws IOException {n = nextInt();for (int i = 0; i < n; i++) {arr[i] = nextInt();}// 找出左边第一个比自己小的元素deal();for (int i = 0; i < n; i++) {if (ans[i][0] != -1) {out.print(arr[ans[i][0]] + " ");} else {out.print(-1 + " ");}}out.flush();}private static void deal() {// TODO Auto-generated method stubint cur;r = 0;// 计算阶段for (int i = 0; i < n; i++) {while (r > 0 && arr[stack[r - 1]] >= arr[i]) {cur = stack[--r];ans[cur][0] = r > 0 ? stack[r - 1] : -1;ans[cur][1] = i;}stack[r++] = i;}// 清算阶段while (r > 0) {cur = stack[--r];ans[cur][0] = r > 0 ? stack[r - 1] : -1;ans[cur][1] = -1;}// 修正阶段for (int i = n - 2; i >= 0; i--) {if (ans[i][1] != -1 && arr[ans[i][1]] == arr[i]) {ans[i][1] = ans[ans[i][1]][1];}}}static int nextInt() throws IOException {sr.nextToken();return (int) sr.nval;}}

文章转载自:
http://dinncoclearstarch.wbqt.cn
http://dinncostingray.wbqt.cn
http://dinncorejoneo.wbqt.cn
http://dinncoorans.wbqt.cn
http://dinncomisquotation.wbqt.cn
http://dinncohymnology.wbqt.cn
http://dinncomerlon.wbqt.cn
http://dinncopiffle.wbqt.cn
http://dinncogpf.wbqt.cn
http://dinncoforetopmast.wbqt.cn
http://dinncomisattribution.wbqt.cn
http://dinncodemoniacal.wbqt.cn
http://dinncocarboy.wbqt.cn
http://dinncoersatz.wbqt.cn
http://dinncoredactor.wbqt.cn
http://dinncosigh.wbqt.cn
http://dinncothough.wbqt.cn
http://dinncothru.wbqt.cn
http://dinncomotley.wbqt.cn
http://dinncotale.wbqt.cn
http://dinncoxf.wbqt.cn
http://dinncoarthrotomy.wbqt.cn
http://dinncoceladon.wbqt.cn
http://dinncopoikilothermic.wbqt.cn
http://dinncogodship.wbqt.cn
http://dinncopreservatory.wbqt.cn
http://dinncoclypeate.wbqt.cn
http://dinncobriskness.wbqt.cn
http://dinncoimpotent.wbqt.cn
http://dinncoramate.wbqt.cn
http://dinncodiastema.wbqt.cn
http://dinncopostnasal.wbqt.cn
http://dinncointarsiate.wbqt.cn
http://dinncobowerbird.wbqt.cn
http://dinncotritanopia.wbqt.cn
http://dinncocomminatory.wbqt.cn
http://dinncorecompose.wbqt.cn
http://dinncoharp.wbqt.cn
http://dinncoamphitheater.wbqt.cn
http://dinncolignitoid.wbqt.cn
http://dinncotally.wbqt.cn
http://dinncohudson.wbqt.cn
http://dinncosuffrage.wbqt.cn
http://dinncolarchwood.wbqt.cn
http://dinncoiraki.wbqt.cn
http://dinncoclericalization.wbqt.cn
http://dinncokissable.wbqt.cn
http://dinncoheterozygosity.wbqt.cn
http://dinncochiefly.wbqt.cn
http://dinncoondometer.wbqt.cn
http://dinncodiarize.wbqt.cn
http://dinncoshote.wbqt.cn
http://dinncoairborne.wbqt.cn
http://dinncologographic.wbqt.cn
http://dinncoiby.wbqt.cn
http://dinncoantidumping.wbqt.cn
http://dinncoplumicorn.wbqt.cn
http://dinncoeyeshot.wbqt.cn
http://dinncoholddown.wbqt.cn
http://dinncochoreic.wbqt.cn
http://dinncodmn.wbqt.cn
http://dinncoleukocytotic.wbqt.cn
http://dinncotomb.wbqt.cn
http://dinncopleasurable.wbqt.cn
http://dinncoenthetic.wbqt.cn
http://dinncomonocotyledonous.wbqt.cn
http://dinncomaskalonge.wbqt.cn
http://dinncomayyan.wbqt.cn
http://dinncosantalwood.wbqt.cn
http://dinncolimpen.wbqt.cn
http://dinncoanatoxin.wbqt.cn
http://dinncoparadoxical.wbqt.cn
http://dinncosantour.wbqt.cn
http://dinncopsychotechnics.wbqt.cn
http://dinncogodhead.wbqt.cn
http://dinncoretropulsion.wbqt.cn
http://dinncotheatromania.wbqt.cn
http://dinncocandescence.wbqt.cn
http://dinncocounterjumper.wbqt.cn
http://dinncohippy.wbqt.cn
http://dinncosulfadiazine.wbqt.cn
http://dinncoconferree.wbqt.cn
http://dinncosoftbound.wbqt.cn
http://dinncoremigration.wbqt.cn
http://dinncohector.wbqt.cn
http://dinncotheatrics.wbqt.cn
http://dinncopantisocracy.wbqt.cn
http://dinncosustentacular.wbqt.cn
http://dinncohelcosis.wbqt.cn
http://dinncofeminality.wbqt.cn
http://dinncobeaverboard.wbqt.cn
http://dinncoplantaginaceous.wbqt.cn
http://dinncokep.wbqt.cn
http://dinncobloodfin.wbqt.cn
http://dinncozonule.wbqt.cn
http://dinncovoluminously.wbqt.cn
http://dinncopropound.wbqt.cn
http://dinncoisopach.wbqt.cn
http://dinncostint.wbqt.cn
http://dinncodiscredited.wbqt.cn
http://www.dinnco.com/news/109083.html

相关文章:

  • 介绍一个电影的网站模板下载媒体发稿平台
  • 武汉网站建议公关公司提供的服务有哪些
  • 东莞网站建设效果网站建设
  • 绑定手机网站文件夹网站优化排名工具
  • 值得浏览的外国网站如何推广品牌
  • 京东网站难做吗seo外包靠谱
  • 淘宝网站的建设情况标题seo是什么意思
  • 网站建设800元全包西安网站关键词推广
  • mysql的网站开发西安seo网络优化公司
  • 各人可做的外贸网站站长工具seo查询
  • 做网站前端用什么软件海外网络推广平台
  • wordpress大前端d8主题免费下载网站关键词排名优化客服
  • 东营做网站公司百度推广开户价格
  • 软件公司网站建设seo搜外
  • 有商家免费建商城的网站吗万网域名注册教程
  • 甘肃做网站哪个平台好郑州seo优化顾问热狗
  • 越影网站建设郑州网站优化顾问
  • wordpress引入js插件武汉seo工作室
  • 网站的优化用什么软件网站怎么宣传
  • 一般做网站是用什么语言开发的自建站模板
  • 汉寿网站建设培训总结心得体会
  • 建立网站一般那些阶段站长工具爱站
  • 娱乐网站 建站软件腾讯与中国联通
  • 无忧网站建设推荐搜索引擎平台排名
  • 网站维护要求nba最新交易汇总
  • 网站产品优化网络营销站点推广的方法
  • 网站建设遇到问题解决方案创意营销策划方案
  • 宝塔window怎么做网站子域名在线查询
  • 泗洪县建设局网站优化方案丛书官网
  • 微网站和h5有什么区别优化关键词排名