Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
放爷算法6907ms,因为一个地方王记判断队列是否为空re了好几次。。。#include <iostream> #include <deque> #include <stdio.h> using namespace std; int data[1000010]; deque<int> fangyeMin, fangyeMax; int main() { int n, k; scanf("%d%d", &n, &k); for(int i = 0; i < n; i++){ scanf("%d", &data[i]); } for(int i = 0; i < k-1; i++){ while(!fangyeMin.empty() && data[fangyeMin.back()] >= data[i]){ fangyeMin.pop_back(); } fangyeMin.push_back(i); } for(int i = k-1; i < n; i++){ if(!fangyeMin.empty() && fangyeMin.front() == i - k) fangyeMin.pop_front(); while(!fangyeMin.empty() && data[fangyeMin.back()] >= data[i]){ fangyeMin.pop_back(); } fangyeMin.push_back(i); printf("%d ", data[fangyeMin.front()]); } printf("\n"); for(int i = 0; i < k-1; i++){ while(!fangyeMax.empty() && data[fangyeMax.back()] <= data[i]){ fangyeMax.pop_back(); } fangyeMax.push_back(i); } for(int i = k-1; i < n; i++){ if(!fangyeMax.empty() && fangyeMax.front() == i - k) fangyeMax.pop_front(); while(!fangyeMax.empty() && data[fangyeMax.back()] <= data[i]){ fangyeMax.pop_back(); } fangyeMax.push_back(i); printf("%d ", data[fangyeMax.front()]); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator