Algorithms for the exam in the SHAD

Hello! My name is Alexander Kurilkin, and I am teaching a course on algorithms at ShAD Helper. In this post, I will analyze several tasks from the entrance exams of past years, so that you can see what awaits you and understand what we can teach you in our course. I hope that you share my love for interesting tasks on algorithms and will receive sincere pleasure from reading this post! So, let's get started ...



05/28/2016, No. 4


Are given nsegments [ai;bi]. We call the segment nesting index[ai;bi]the number of segments that contain it. Suggest an algorithm that determines whether there is a segment in the set with a nesting index exceeding 1000. The time limit isO(nlog⁑n), for additional memory - O(n).


Decision

, "". , - , , - , . " ", ai, " ", bi. . , 1. , 1000, , β€” 1000 . β€” - , , . , (std::multiset C++), . , β€” 1000 . , , , , *set.begin(), ( 1000 ) . , ! , , . , . , , !


: 1000 ? , - 1000 , 1000 , - , ? , - 1000 , , , , , .


, . O(nlog⁑n), O(nlog⁑1000)=O(n)O(n) . , : O(nlog⁑n). O(n).


05/25/2019, No.4


An array of real numbers is given A. Suggest an algorithm that finds for each elementAindex of the element closest to the right, at least twice its size. If there is no such element, then the value should be returned.None. Time limitO(nlog⁑n), for additional memory - O(n).


Decision

(,). ( None), (A[nβˆ’1],nβˆ’1), . i. , , , ? , . , , , ? . , . , (A[i],i). , , ? , ( ) i. (, , std::vector) , A[i]β‹…2. , ( ), , None.


, , ? , O(n), n, O(nlog⁑n), . , , , O(n).


06/10/12, No. 5
In the set ofn each person may or may not know the other (if Aknows B, it does not follow that Bknows A) All acquaintances are given by a Boolean matrixnΓ—n. β€” , , . , , . β€” O(n), β€” O(1).


Kij=1, i- j- , 0 .


, Kij=1 (iβ‰ j), i- , - , j- , Kij=0, j- , i- .


: β€” . , 1, , l. , ( 0), , , , , - ( , , l). l- β€” , (l,l+1). 1, , , . , . , , , ( ), , , , . , , , O(n), , O(n). : O(n). , , (, ), O(1). !


, , !


2019, -, D


, 2
: 2
: 256Mb


nm. qΒ« i1Β». .


β€” , . , .


. , , .



nmβ€” (1≀n,m≀105,2≀n). mu, v, w. , w, uv(1≀u,v≀n,1≀w≀10).


qβ€” (1≀q≀105). qid(1≀id≀m). , id. .



qnumbers separated by spaces or line breaks - the weight of the minimum spanning tree after each request.


Decision

, , 99% . .


" uv", k. uvk( . k+1, , uv>k+1, k+1, , ́ ), , 1. . , , . O(n), , , O(log⁑n)link-cut tree, , ( ). .


1 10, 10 ( , ). k- ≀k. . : , ( ) , , . , , , , .


(u,v)1 k. k- . , k- uv. , k+1, , . , uvk- , 1. uvk- , ≀k, .


, , ? O(Ξ±(n)), O(10β‹…mlog⁑n)=O(mlog⁑n). , Accepted :)


All Articles