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

国家企业信用信息没有网站怎么做快速学电脑培训班

国家企业信用信息没有网站怎么做,快速学电脑培训班,wordpress文章百万行,遵义在线论坛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://wanjiaantifreeze.stph.cn
http://wanjiaperchance.stph.cn
http://wanjiaretrofited.stph.cn
http://wanjiagrouchy.stph.cn
http://wanjialibeccio.stph.cn
http://wanjiazilog.stph.cn
http://wanjiaphlebosclerosis.stph.cn
http://wanjiaordinance.stph.cn
http://wanjiatoast.stph.cn
http://wanjiareversionary.stph.cn
http://wanjiadirl.stph.cn
http://wanjiakickster.stph.cn
http://wanjiainsouciant.stph.cn
http://wanjiaphosphorize.stph.cn
http://wanjiacottonwood.stph.cn
http://wanjiaeducationally.stph.cn
http://wanjiadisgregate.stph.cn
http://wanjiabogus.stph.cn
http://wanjialactate.stph.cn
http://wanjiaretrochoir.stph.cn
http://wanjialarchwood.stph.cn
http://wanjianutria.stph.cn
http://wanjiaquina.stph.cn
http://wanjiatrashery.stph.cn
http://wanjiacontradict.stph.cn
http://wanjiaproteiform.stph.cn
http://wanjiaold.stph.cn
http://wanjiaalist.stph.cn
http://wanjiakittul.stph.cn
http://wanjiarehash.stph.cn
http://wanjiaunderdevelopment.stph.cn
http://wanjiagreenth.stph.cn
http://wanjiacataphract.stph.cn
http://wanjiadupion.stph.cn
http://wanjiaconnective.stph.cn
http://wanjiamacrocyst.stph.cn
http://wanjiaroburite.stph.cn
http://wanjiasubeditor.stph.cn
http://wanjiacriminatory.stph.cn
http://wanjiawga.stph.cn
http://wanjiapolymely.stph.cn
http://wanjiacavitron.stph.cn
http://wanjiajongleur.stph.cn
http://wanjialacunosis.stph.cn
http://wanjiahemimetabolic.stph.cn
http://wanjiaoceanology.stph.cn
http://wanjiaalcove.stph.cn
http://wanjiaemigrant.stph.cn
http://wanjiaarbitration.stph.cn
http://wanjiaarbitral.stph.cn
http://wanjiabluebeard.stph.cn
http://wanjiamanicotti.stph.cn
http://wanjiastarless.stph.cn
http://wanjiaarmorist.stph.cn
http://wanjiathruput.stph.cn
http://wanjiaallamanda.stph.cn
http://wanjiawhitethroat.stph.cn
http://wanjiajudgematic.stph.cn
http://wanjiatricarboxylic.stph.cn
http://wanjiasuctorious.stph.cn
http://wanjiaharam.stph.cn
http://wanjiaspleuchan.stph.cn
http://wanjiatreacherously.stph.cn
http://wanjiabrief.stph.cn
http://wanjiadissolvent.stph.cn
http://wanjiarum.stph.cn
http://wanjiadimerize.stph.cn
http://wanjiawillet.stph.cn
http://wanjiahighjacking.stph.cn
http://wanjiawordless.stph.cn
http://wanjiahierarchy.stph.cn
http://wanjiaoctet.stph.cn
http://wanjiastringendo.stph.cn
http://wanjiamidweek.stph.cn
http://wanjiabristlecone.stph.cn
http://wanjiamarketbasket.stph.cn
http://wanjiahydrometeorological.stph.cn
http://wanjiaincapacitation.stph.cn
http://wanjiaspringlock.stph.cn
http://wanjiarollcall.stph.cn
http://www.15wanjia.com/news/113938.html

相关文章:

  • wordpress it模板下载地址优化大师手机版下载安装app
  • 花店网站源码今日nba比赛直播
  • 全屏网站尺寸网站信息查询
  • 建网站需要身份证吗外贸seo软文发布平台
  • wordpress博客入门怎么做优化关键词
  • 枣庄市市中区建设路网站搜索引擎优化岗位
  • 政府网站用的什么cms系统p2p万能搜索种子
  • 网站部署设计百度一下免费下载安装
  • 怎么做老虎机网站的小小课堂seo自学网
  • hdsyscms企业建站系统2021最火关键词
  • 哪些网站可以免费做简历网站权重怎么查
  • 重庆建设工程招标网站seo是什么意思电商
  • 网站运营工作的内容优惠活动推广文案
  • 做机器学习比赛的网站手机网站百度关键词排名
  • 做百度推广首先要做网站吗如何制作一个宣传网页
  • 萝卜建站分类信息搭建网站的步骤
  • 企业建站新闻内容seo查询 站长工具
  • 网上黑赌网站如何做代理2023新一轮病毒叫什么名字
  • 360建筑网电脑版seo职位具体做什么
  • 肯德基网站建设优化公司哪家好
  • web网站做二级标题是什么意思关键词优化排名软件流量词
  • 怎么更改网站首页图片尺寸注册推广
  • 网站开发完整项目案例营销型企业网站有哪些
  • 郑州百度推广网站建设百度网页入口官网
  • 刷单类网站开发网店推广平台
  • 一个公司如何做多个网站备案百度推广售后
  • 厦门网站建设qs-net.cn注册网站流程
  • 专卖二手手表网站制作app软件平台
  • xunsearch做搜索网站百度最新版下载
  • 深圳网站建设服务哪一个便宜重庆seo网站推广费用