Afişează mesaje
|
Pagini: 1 ... 4 5 [6] 7 8 ... 57
|
140
|
Comunitate - feedback, proiecte si distractie / Blog / Răspuns: Coding Cotest Byte: The Square Root Trick
|
: Iulie 27, 2012, 02:26:26
|
Yes, basically you work with 2k + 1 lists instead of working with n numbers. First you have one list, then three and so on.
For each list you know the start index and end index. Reversing a list means swapping it's boundaries.
Reversing a new range involves creating 2 new lists and reversing all the lists that are within the current range. If you have x lists, doing an update takes O(x).
So doing sqrt(n) offline reverse updates takes O(sqrt(n) * sqrt(n) + n) = O(n) time.
|
|
|
141
|
Comunitate - feedback, proiecte si distractie / Blog / Răspuns: Coding Cotest Byte: The Square Root Trick
|
: Iulie 27, 2012, 02:00:41
|
let's see what happens for n = 10 and reverse(3,7) reverse(5,9)
first you have the whole range [1..10]
[1,2] [3,4,5,6,7] [8,9,10] reverse(3,7) [1,2], [7, 6, 5, 4, 3] [8, 9, 10]
[1,2] [7, 6] [5, 4, 3] [8, 9] [10] reverse(5, 10) [1, 2] [7, 6] [9, 8] [3, 4, 5] [10]
So the idea is that you play with compact lists of consecutive indexes. Each update increases the number of lists by 2 and reverses the order of the lists.
|
|
|
147
|
Comunitate - feedback, proiecte si distractie / Blog / Răspuns: Coding Cotest Byte: The Square Root Trick
|
: Iulie 20, 2012, 22:02:28
|
I made a mistake in the median problem. I updated the query complexity to be O(sqrt(n)log(n)log(U)).
@Andrei, your solutions look correct.
Here are two other problems: 1. You are given 2 eggs. You have access to a 100-story building. Eggs can be very hard or very fragile means it may break if dropped from the first floor or may not even break if dropped from 100 th floor.Both eggs are identical. You need to figure out the highest floor of a 100-storey building an egg can be dropped without breaking. Now the question is how many drops you need to make. You are allowed to break 2 eggs in the process. 2. Compute the number of digits of n! n <= 1000000000
|
|
|
|