Acwing.154 滑动窗口

您所在的位置:网站首页 python输入三个整数输出最大值最小值 Acwing.154 滑动窗口

Acwing.154 滑动窗口

#Acwing.154 滑动窗口| 来源: 网络整理| 查看: 265

题目

给定一个大小为n ≤10^6的数组。 有一个大小为k的滑动窗口,它从数组的最左边移动到最右边。 您只能在窗口中看到k个数字。每次滑动窗口向右移动一个位置。以下是一个例子: 该数组为[13-1-35367],k为3。 在这里插入图片描述

您的任务是确定滑动窗口位于每个位置时,窗口中的最大值和最小值。

输入格式

输入包含两行。 第一行包含两个整数n和k,分别代表数组长度和滑动窗口的长度。第二行有n个整数,代表数组的具体数值。 同行数据之间用空格隔开。

输出格式

输出包含两个。 第一行输出,从左至右,每个位置滑动窗口中的最小值。第二行输出,从左至右,每个位置滑动窗口中的最大值。

输入样例: 8 3 1 3 -1 -3 5 3 6 7 输出样例: -1 -3 -3 -3 3 3 3 3 5 5 6 7 题解 import java.util.Scanner; /** * @author akuya * @create 2023-06-26-20:35 */ public class SlidingWindow { static int N=1000010; static int n,k; static int a[]=new int[N]; static int q[]=new int[N]; public static void main(String[] args) { Scanner scanner=new Scanner(System.in); n=scanner.nextInt(); k=scanner.nextInt(); for(int i=0;i if(hhq[hh])hh++; while(hh


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3