Returns the N number, n <= 250000, calculates the median of the N number, and the memory limit is 1 MB.
Card memory God question, with the array to save just 1 MB, coupled with the runtime consumption of memory, immediately burst. Therefore, we use the priority queue to store half of the data. Some code on the Internet uses priority_queue to blow up the memory. The 125000-length array I saved, plus the STL make_heap ()
# Include <cstdio> # include <queue> using namespace STD; int A [125010]; int main () {int n, x; double ans; scanf ("% d ", & N); For (INT I = 0; I <n/2 + 1; I ++) scanf ("% d", & A [I]); make_heap (A, A + n/2 + 1); For (INT I = n/2 + 1; I <n; I ++) {scanf ("% d ", & X); If (x <A [0]) {pop_heap (A, A + n/2 + 1); A [n/2] = x; push_heap (, A + n/2 + 1) ;}}if (N & 1) ans = (double) A [0]; else {ans = (double) A [0]; pop_heap (A, A + n/2 + 1); ans + = (double) A [0]; ans = ANS/2.0;} printf ("%. 1lf \ n ", ANS );}
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.
Ural1306 sequence median (card memory)