SpringBoot中properties,yml,yaml的區(qū)別及使用說明
SpringBoot中的properties,yml,yaml的區(qū)別
概述
- SpringBoot中提供了兩種配置文件properties和yml/yaml(yml和yaml是同一個意思)
- 默認配置文件名稱:application
- 在同一目錄下的時候優(yōu)先級為:properties>yml>yaml
書寫格式
通過修改訪問接口,來演示配置
properties:
server.port=8080
- yml:
server: port: 8080
需要注意的是對于yml語法的:后面要加一個空格。
滑動窗口
- 給定一個大小為 n≤106 的數組。
- 有一個大小為 k 的滑動窗口,它從數組的最左邊移動到最右邊。
- 你只能在窗口中看到 k 個數字。
- 每次滑動窗口向右移動一個位置。
以下是一個例子:
該數組為 [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
你的任務是確定滑動窗口位于每個位置時,窗口中的最大值和最小值。
- 輸入格式
- 輸入包含兩行。
第一行包含兩個整數 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
提交代碼
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隊列里面存放的是位置
{
scanf ("%d", &a[i]); // 先求的是最小值
if (i - k + 1 > q[hh]) ++hh; // 如果最小值的位置已經滑出窗口了 然后就
// ++ hh代表這個數已經沒了
while (hh <= tt && a[i] <= a[q[tt]]) -- tt; // 先確保隊列里面有數字
// 然后如果新來的數字要小于 隊列里面的最小值
// 那么--tt 就代表當前隊列的最小值去掉
q[++ tt] = i; // 把新來的數字放到隊列中
if (i + 1 >= k) printf ("%d ", a[q[hh]]); // 當前隊列的長度已經滿足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++;//判斷隊頭是否已經滑出窗口
while(hh <= tt && a[q[tt]] >= a[i]) tt--;//出隊
q[++tt] = i;//入隊
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++;//判斷隊頭是否已經滑出窗口
while(hh <= tt && a[q[tt]] <= a[i]) tt--;//出隊
q[++tt] = i;//入隊
if(i >= k - 1) out.write(a[q[hh]]+" ");
}
out.flush();
out.close();
}
}總結
以上為個人經驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
使用Spring Data R2DBC +Postgres實現增刪改查功能
這篇文章主要介紹了使用Spring Data R2DBC +Postgres實現增刪改查功能,本文通過兩種方法給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-03-03

