网络一站式服务平台,网络营销的主要方式k,为什么大型网站都用php,科技公司网站模板下载#x1f4d1;前言
本文主要是【算法】——蓝桥杯练习题#xff08;九#xff09;的文章#xff0c;如果有什么需要改进的地方还请大佬指出⛺️ #x1f3ac;作者简介#xff1a;大家好#xff0c;我是听风与他#x1f947; ☁️博客首页#xff1a;CSDN主页听风与他 …前言
本文主要是【算法】——蓝桥杯练习题九的文章如果有什么需要改进的地方还请大佬指出⛺️ 作者简介大家好我是听风与他 ☁️博客首页CSDN主页听风与他 每日一句狠狠沉淀顶峰相见 目录 前言1142.百亿富翁1207.MAX最值差2219.左移右移文章末尾 1142.百亿富翁
package 蓝桥杯第九次;import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;public class 百亿富翁 {
/*
5
3 1 2 5 4*/public static void main(String[] args) throws IOException {// TODO Auto-generated method stubStreamTokenizer sc new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));sc.nextToken();int n (int)sc.nval;long a[] new long[n1];for(int i1;in;i) {sc.nextToken();a[i](long)sc.nval;}int num1[] new int[n1];int num2[] new int[n1];Arrays.fill(num1, -1);Arrays.fill(num2, -1);DequeInteger q new ArrayDeque();//按顺序遍历for(int i1;in;i) {while(!q.isEmpty()a[q.peekLast()]a[i]) q.pollLast();if(!q.isEmpty()) {num1[i]q.peekLast();}q.add(i);}q.clear();//倒过来遍历就是右边第一栋比自己高for(int in;i1;i--) {while(!q.isEmpty()a[q.peekLast()]a[i]) q.pollLast();if(!q.isEmpty()) {num2[i]q.peekLast();}q.add(i);}for(int i1;in;i) {System.out.print(num1[i] );}System.out.println();for(int i1;in;i) {System.out.print(num2[i] );}}}
1207.MAX最值差
package 蓝桥杯第九次;import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.ArrayDeque;
import java.util.Deque;public class MAX最值差 {public static void main(String[] args) throws IOException {// TODO Auto-generated method stubStreamTokenizer sc new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));sc.nextToken();int n (int)sc.nval;sc.nextToken();int k (int)sc.nval;int a[] new int[n1];for(int i1;in;i) {sc.nextToken();a[i] (int)sc.nval;}DequeInteger q new ArrayDeque();int num1[] new int[n1];int num2[] new int[n1];for(int i1;in;i) {while(!q.isEmpty()i-kq.peekFirst()) q.pollFirst();while(!q.isEmpty()a[i]a[q.peekLast()]) q.pollLast();q.addLast(i);num1[i]q.peekFirst();}q.clear();for(int i1;in;i) {while(!q.isEmpty()i-kq.peekFirst()) q.pollFirst();while(!q.isEmpty()a[i]a[q.peekLast()]) q.pollLast();q.addLast(i);num2[i]q.peekFirst();}int max Integer.MIN_VALUE;for(int i1;in;i) {max Math.max(a[num2[i]]-a[num1[i]], max);}System.out.println(max);}
/*
6 3
4 6 5 2 3 1*/
}
2219.左移右移
package 蓝桥杯第九次;import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;public class 左移右移2 {static class Node{int val;;Node pre;Node next;public Node(int val,Node pre,Node next) {this.val val;this.pre pre;this.next next;}}public static void main(String[] args) {// TODO Auto-generated method stubScanner sc new Scanner(System.in);int n sc.nextInt();int m sc.nextInt();MapInteger, Node map new HashMap();Node head new Node(-1, null, null);Node tail new Node(-1, null, null);Node pre head;for(int i1;in;i) {pre.next new Node(i, pre, null);pre pre.next;map.put(i, pre);}pre.next tail;tail.pre pre;while(m--0) {char c sc.next().charAt(0);int k sc.nextInt();Node node map.get(k);node.next.pre node.pre;node.pre.next node.next;if(cL) {head.next.pre node;node.next head.next;head.next node;node.pre head;}else {node.pre tail.pre;tail.pre.next node;node.next tail;tail.pre node;}}Node cur head.next;while(cur!tail) {System.out.print(cur.val );cur cur.next;}}}
文章末尾