最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

SpringBoot中properties,yml,yaml的區(qū)別及使用說明

 更新時間:2025年03月14日 11:23:16   作者:極客李華  
這篇文章主要介紹了SpringBoot中properties,yml,yaml的區(qū)別及使用說明,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教

SpringBoot中的properties,yml,yaml的區(qū)別

概述

  • SpringBoot中提供了兩種配置文件properties和yml/yaml(yml和yaml是同一個意思)
  • 默認(rèn)配置文件名稱:application
  • 在同一目錄下的時候優(yōu)先級為:properties>yml>yaml

書寫格式

通過修改訪問接口,來演示配置

properties:

server.port=8080
  • yml:
server:
	port: 8080

需要注意的是對于yml語法的:后面要加一個空格。

滑動窗口

  • 給定一個大小為 n≤106 的數(shù)組。
  • 有一個大小為 k 的滑動窗口,它從數(shù)組的最左邊移動到最右邊。
  • 你只能在窗口中看到 k 個數(shù)字。
  • 每次滑動窗口向右移動一個位置。

以下是一個例子:

該數(shù)組為 [1 3 -1 -3 5 3 6 7],k 為 3。

窗口位置 最小值 最大值
[1 3 -1] -3 5 3 6 7 -1 3
1 [3 -1 -3] 5 3 6 7 -3 3
1 3 [-1 -3 5] 3 6 7 -3 5
1 3 -1 [-3 5 3] 6 7 -3 5
1 3 -1 -3 [5 3 6] 7 3 6
1 3 -1 -3 5 [3 6 7] 3 7

你的任務(wù)是確定滑動窗口位于每個位置時,窗口中的最大值和最小值。

  • 輸入格式
  • 輸入包含兩行。

第一行包含兩個整數(shù) n 和 k,分別代表數(shù)組長度和滑動窗口的長度。

第二行有 n 個整數(shù),代表數(shù)組的具體數(shù)值。

同行數(shù)據(jù)之間用空格隔開。

  • 輸出格式
  • 輸出包含兩個。

第一行輸出,從左至右,每個位置滑動窗口中的最小值。

第二行輸出,從左至右,每個位置滑動窗口中的最大值。

  • 輸入樣例:

8 3

1 3 -1 -3 5 3 6 7

  • 輸出樣例:

-1 -3 -3 -3 3 3
3 3 5 5 6 7

提交代碼

C++

#include<iostream>
using namespace std;

const int N = 1000010;
int a[N], q[N], hh, tt = -1;

int main()
{
    int n, k;
    cin >> n >> k;
    for (int i = 0; i < n; ++ i)    // 這個題要注意的是 q隊(duì)列里面存放的是位置
    {
        scanf ("%d", &a[i]);        // 先求的是最小值
        if (i - k + 1 > q[hh]) ++hh;  // 如果最小值的位置已經(jīng)滑出窗口了 然后就
                                    // ++ hh代表這個數(shù)已經(jīng)沒了
        while (hh <= tt && a[i] <= a[q[tt]]) -- tt; // 先確保隊(duì)列里面有數(shù)字
                                    // 然后如果新來的數(shù)字要小于 隊(duì)列里面的最小值
                                    // 那么--tt 就代表當(dāng)前隊(duì)列的最小值去掉
        q[++ tt] = i;  // 把新來的數(shù)字放到隊(duì)列中
        if (i + 1 >= k) printf ("%d ", a[q[hh]]); // 當(dāng)前隊(duì)列的長度已經(jīng)滿足k了
                                    // 就可以把對首的元素輸出出來
    }
    puts("");
    int hh = 0, tt = -1;
    for (int i = 0; i < n; ++ i)
    {
        if (i - k + 1 > q[hh]) ++ hh;
        while (hh <= tt && a[i] >= a[q[tt]]) -- tt;
        q[++ tt] = i;
        if (i + 1 >= k) printf("%d ", a[q[hh]]);
    }
    return 0;
}

Java

import java.io.*;

public class Main
{
    final static int N = 1000010;
    static int [] a = new int [N];
    static int [] q = new int [N];
    static int hh = 0, tt = -1;
    public static void main(String[] args) throws IOException
    {
        int n, k;
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
        
        String [] str = reader.readLine().split(" ");
        n = Integer.parseInt(str[0]);
        k = Integer.parseInt(str[1]);
        
        str = reader.readLine().split(" ");
        for (int i = 0; i < n; ++ i) a[i] = Integer.parseInt(str[i]);
        
        // for (int i = 0; i < n; ++ i)
        // {
        //     if (hh <= tt && i - k + 1 > q[hh])  ++ hh;
        //     while (hh <= tt && a[i] <= a[q[hh]]) -- tt;
        //     q[++ tt] = i;
        //     if (i + 1 >= k) out.write(a[q[hh]]+" ");
        // }
        
        for(int i = 0; i < n; i ++)
        {
            if(hh <= tt && i - q[hh] + 1 > k) hh++;//判斷隊(duì)頭是否已經(jīng)滑出窗口
            while(hh <= tt && a[q[tt]] >= a[i]) tt--;//出隊(duì)

            q[++tt] = i;//入隊(duì)
            if(i >= k - 1) out.write(a[q[hh]]+" ");
        }
        
        out.write("\n");
        hh = 0;
        tt = -1;
        // for (int i  = 0; i < n; ++ i)
        // {
        //     if (hh <= tt && i - k + 1 > q[hh]) ++ hh;
        //     while (hh <= tt && a[i] >= a[q[hh]]) -- tt;
        //     q[++ tt] = i;
        //     if (i + 1 >= k) out.write(a[q[hh]]+" ");
        // }
        for(int i = 0; i < n; i ++)
        {
            if(hh <= tt && i - q[hh] + 1 > k) hh++;//判斷隊(duì)頭是否已經(jīng)滑出窗口
            while(hh <= tt && a[q[tt]] <= a[i]) tt--;//出隊(duì)

            q[++tt] = i;//入隊(duì)
            if(i >= k - 1) out.write(a[q[hh]]+" ");
        }
        out.flush();
        out.close();
    }
}

總結(jié)

以上為個人經(jīng)驗(yàn),希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

枣阳市| 宝鸡市| 平昌县| 临海市| 永善县| 长寿区| 绥中县| 元谋县| 启东市| 正安县| 南汇区| 府谷县| 青岛市| 三穗县| 清河县| 泸定县| 高雄县| 高唐县| 饶阳县| 肇州县| 龙南县| 汉沽区| 临猗县| 神木县| 潮州市| 宁明县| 嘉黎县| 鱼台县| 滕州市| 晋中市| 大洼县| 日喀则市| 穆棱市| 马龙县| 清流县| 格尔木市| 丰宁| 泸西县| 额济纳旗| 弥渡县| 望奎县|