【东莞中学2013暑假训练题(一)】Window

This commit is contained in:
James 2020-04-24 18:26:27 +08:00
parent b4de50b5d1
commit de87f59713
10 changed files with 96 additions and 2 deletions

View File

@ -1,3 +1,28 @@
# 标题
# 【东莞中学2013暑假训练题】Window
* 内容
题目描述
  给你一个长度为N的数组一个长为K的滑动的窗体从最左移至最右端你只能见到窗口的K个数每次窗体向右移动一位如下表
  
  你的任务是找出窗口在各位置时的max valuemin value。
输入输出格式
输入格式:
  第1行nk。
  第2行长度为n的数组。
输出格式:
  2行第1行每个位置的min value,第2行每个位置的max value。
输入输出样例
输入样例#1
8 3
1 3 -1 -3 5 3 6 7
输出样例#1
-1 -3 -3 -3 3 3
3 3 5 5 6 7
提示信息
  数据范围:
  20% n<=500
  50%: n<=100000
  100%: n<=1000000。

3
gz3628_window/Readme.md Normal file
View File

@ -0,0 +1,3 @@
# 标题
* 内容

View File

@ -0,0 +1,3 @@
# 标题
* 内容

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

40
gz3628_window/main.cpp Normal file
View File

@ -0,0 +1,40 @@
#include <iostream>
using namespace std;
int nn, zhe, a[1000001] = { 0 };
int tou = 0, wei = 0, f[1000001] = { 0 }, pai[1000001] = { 0 };
int main()
{
cin >> nn >> zhe;
for (int i = 1; i <= nn; i++) {
cin >> a[i];
}
for (int i = 1; i <= nn; i++) {
//cout << f[i - 1] << pai[i - 1] << endl;
while (tou < wei && i - pai[tou] >= zhe) {
tou++;
}
while (tou < wei && f[wei-1] > a[i]) {
wei--;
}
f[wei] = a[i];
pai[wei++] = i;
if (i >= zhe) {
cout << f[tou] << " ";
}
}
cout<<endl;
tou = 0, wei = 0, pai[1] = 0, f[1] = 0;
for (int i = 1; i <= nn; i++) {
while (tou < wei && i - f[tou] >= zhe) {
tou++;
}
while (tou < wei && f[wei-1] < a[i]) {
wei--;
}
f[wei] = a[i];
pai[wei++] = i;
if (i >= zhe) {
cout << f[tou] << " ";
}
}
}

BIN
gz3628_window/main.exe Normal file

Binary file not shown.

View File

@ -0,0 +1,2 @@
8 3
1 3 -1 -3 5 3 6 7

View File

View File

View File

@ -0,0 +1,21 @@
## z:\Chao\src\gz3628_window\test\in.txt
2020/04/24 ÖÜÎå 18:23:35.11
-1 -3 -3 -3 3 3
3 3 5 5 6 7
-----------------------------------------------
Process exited after 230 ms with return value 0
## z:\Chao\src\gz3628_window\test\in2.txt
2020/04/24 ÖÜÎå 18:23:35.11
-----------------------------------------------
Process exited after 90 ms with return value 0
## z:\Chao\src\gz3628_window\test\in3.txt
2020/04/24 ÖÜÎå 18:23:35.11
-----------------------------------------------
Process exited after 240 ms with return value 0