The difference between properties, yml, yaml in SpringBoot
Overview
- SpringBoot provides two configuration files properties and yml/yaml (yml and yaml have the same meaning)
- Default configuration file name: application
- When the priority is: properties>yml>yaml
Writing format
Demonstrate configuration by modifying the access interface
properties:
=8080
- yml:
server: port: 8080
It should be noted that foryml
Syntax:
Add a space afterwards.
Sliding window
- Given an array of size n≤106.
- There is a sliding window of size k that moves from the leftmost to the rightmost to the rightmost to the array.
- You can only see k numbers in the window.
- Each time the window slides, moves one position to the right.
Here is an example:
The array is [1 3 -1 -3 5 3 6 7] and k is 3.
Window position Minimum value Maximum value
[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
Your task is to determine the maximum and minimum values in the window when the sliding window is located at each position.
- Input format
- The input contains two lines.
The first line contains two integers n and k, representing the length of the array and the length of the sliding window, respectively.
The second line has n integers, representing the specific numerical values of the array.
Separate the peer data with spaces.
- Output format
- The output contains two.
The first line outputs, from left to right, the minimum value in the window slides from each position.
The second line outputs, from left to right, the maximum value in the window slides from each position.
- Enter a sample:
8 3
1 3 -1 -3 5 3 6 7
- Output sample:
-1 -3 -3 -3 3 3
3 3 5 5 6 7
Submit code
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) // In this question, you should pay attention to the location stored in the q queue. { scanf ("%d", &a[i]); // The minimum value is found first if (i - k + 1 > q[hh]) ++hh; // If the minimum value position has already slipped out of the window, then // ++ hh means that this number is gone while (hh <= tt && a[i] <= a[q[tt]]) -- tt; // Make sure there are numbers in the queue first // Then if the new number is smaller than the minimum value in the queue // Then --tt means the minimum value of the current queue q[++ tt] = i; // Put the new number in the queue if (i + 1 >= k) printf ("%d ", a[q[hh]]); // The length of the current queue has met k // You can output the header element } 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 .*; 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()); BufferedWriter out = new BufferedWriter(new OutputStreamWriter()); String [] str = ().split(" "); n = (str[0]); k = (str[1]); str = ().split(" "); for (int i = 0; i < n; ++ i) a[i] = (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) (a[q[hh]]+" "); // } for(int i = 0; i < n; i ++) { if(hh <= tt && i - q[hh] + 1 > k) hh++;//Judge whether the team head has slipped out of the window while(hh <= tt && a[q[tt]] >= a[i]) tt--;//Get out of the team q[++tt] = i;//Enter the team if(i >= k - 1) (a[q[hh]]+" "); } ("\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) (a[q[hh]]+" "); // } for(int i = 0; i < n; i ++) { if(hh <= tt && i - q[hh] + 1 > k) hh++;//Judge whether the team head has slipped out of the window while(hh <= tt && a[q[tt]] <= a[i]) tt--;//Get out of the team q[++tt] = i;//Enter the team if(i >= k - 1) (a[q[hh]]+" "); } (); (); } }
Summarize
The above is personal experience. I hope you can give you a reference and I hope you can support me more.