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 的數(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
你的任務是確定滑動窗口位于每個位置時,窗口中的最大值和最小值。
- 輸入格式
- 輸入包含兩行。
第一行包含兩個整數(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隊列里面存放的是位置 { scanf ("%d", &a[i]); // 先求的是最小值 if (i - k + 1 > q[hh]) ++hh; // 如果最小值的位置已經滑出窗口了 然后就 // ++ hh代表這個數(shù)已經沒了 while (hh <= tt && a[i] <= a[q[tt]]) -- tt; // 先確保隊列里面有數(shù)字 // 然后如果新來的數(shù)字要小于 隊列里面的最小值 // 那么--tt 就代表當前隊列的最小值去掉 q[++ tt] = i; // 把新來的數(shù)字放到隊列中 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(); } }
總結
以上為個人經驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
MyBatis版本升級導致OffsetDateTime入?yún)⒔馕霎惓栴}復盤
這篇文章主要介紹了MyBatis版本升級導致OffsetDateTime入?yún)⒔馕霎惓栴}復盤,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-08-08使用Mybatis-Plus實現(xiàn)對象屬性自動填充功能
這篇文章主要介紹了如何使用Mybatis-Plus實現(xiàn)對象屬性自動填充功能,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,感興趣的朋友們下面隨著小編來一起來學習吧2024-01-01C#使用MySQLConnectorNet和MySQLDriverCS操作MySQL的方法
這篇文章主要介紹了C#使用MySQLConnectorNet和MySQLDriverCS操作MySQL的方法,相比普通方法能夠在Windows下簡化很多操作步驟,需要的朋友可以參考下2016-04-04