正式AFO @ 2018-08-08 18:44:01
using namespace std;
int a[1000000]; int n, k; int main(){ queue<int> que; cin >> n >> k; int times = 0; for(int i = 1; i <= n; i++){ cin >> a[i]; } for(int i = 1; i <= n - k + 1; i++){ while(times < k){ if(times == 0) que.push(a[i]); if(a[i + times] < que.back()){ que.pop(); que.push(a[i + times]); } //cout << que.back(); times++; } cout << que.back() << " "; que.pop(); times = 0; } cout << "\n"; que.pop(); for(int i = 1; i <= n - k + 1; i++){ while(times < k){ if(times == 0) que.push(a[i]); if(a[i + times] > que.back()){ que.pop(); que.push(a[i + times]); } times++; } cout << que.back() << " "; que.pop(); times = 0; } return 0; }
by 曹老师 @ 2018-08-08 18:53:54
Markdown 了解一下
@5743377_2002
by 正式AFO @ 2018-08-08 18:57:09
老师好,我是蒟蒻一枚,多多关照,谢谢。
by Sasiyar @ 2019-01-23 16:23:06
#include<iostream>
#include<queue>
using namespace std;
int a[1000000];
int n, k;
int main()
{
queue<int> que;
cin >> n >> k;
int times = 0;
for(int i = 1; i <= n; i++)
{
cin >> a[i];
}
for(int i = 1; i <= n - k + 1; i++)
{
while(times < k)
{
if(times == 0)
que.push(a[i]);
if(a[i + times] < que.back())
{
que.pop();
que.push(a[i + times]);
} //cout << que.back();
times++;
}
cout << que.back() << " ";
que.pop();
times = 0;
}
cout << "\n";
que.pop();
for(int i = 1; i <= n - k + 1; i++)
{
while(times < k)
{
if(times == 0)
que.push(a[i]);
if(a[i + times] > que.back())
{
que.pop();
que.push(a[i + times]);
}
times++;
}
cout << que.back() << " ";
que.pop();
times = 0;
}
return 0;
}
强迫症