How can this problem be solved by mathematically ??? Help please ...
I've tried seeing others code,but failed to understand... :(
problem link ... Here
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
How can this problem be solved by mathematically ??? Help please ...
I've tried seeing others code,but failed to understand... :(
problem link ... Here
Название |
---|
Just use binary search
I know this can be done using binary search,even it is accepted in brute force too... but I want to know mathematical solution too... :)
The idea below was mine, but it failed due to a mistake (or floating point error), you can check out my source code (Pascal). 3392195
At first you can check whether (k*(k+1))>2n. If yes, output -1, for reasons clear below.
You can obviously see, that the number of pipelines at the end are,
1+s_1-1+s_2-1+....s_j-1=n.
So s_1-1 + s_2-1 + .... + s_j-1 = n-1
And 2=<s_i<=k, for all i, 1<=i<=j
So the problem reduces to : Find the minimum number of integers j in range [1..k-1] to make n-1, without taking any one twice.
Now, my idea was to use the biggest numbers in order (ie, k-1, then k-2,...etc.), till the sum of the taken numbers exceeded the part that must be taken after that point.
I mean the following steps *
But the above algo is quite time consuming for extreme cases, say, if the input is 5000000050000001 100000001 ( you can easily understand why? :) )
Now, to improve it. In the above what we are effectively doing is to find the point at which the inequality in the while loop ( ie, n>k) goes false. If the loop would have been executed, then k would have value, say k-a. So the following inequality holds true.
n-(k-1 + k-2 + .... k-a+1) < k-a.
Solving this inequality, you will get some bound for a, isn't it?
But notice, the expression:
n-(k-1 + k-2 + ... k-a+1 + k-a)
is quadratic in a, ie its in terms of a^2.
So its solution ( by Shreedharacharya's method :) ) will involve squares and square roots ( You can have a look at my soln, or its C++ version 3408435 ) . And square roots, as you know, are notorious operations, floating point errors are quite common. So, I feel, some care is needed in implementing this routine.
But remember, I might be wrong. After all, my rating speaks :) :( Any errors, please tell me, perhaps here, or perhaps in the Talks section of cf.
mbrc wrote,
But this seems too big for some values, so consider, that at point a the above happens, then n-(k-1 + k-2 + .... k-a+1) < k_a. Solving this inequality, you will get some bound for a. But this one's a quadratic inequality. So floating point issues will creep in :(
could not get this... :( My bad.... :( I am failed to solve this portion mathematically... would you try one more time,please ?
বাঙ্গালী দেখে ভাল লাগছে ... :)
Updated the comment. :)
Look at this one. This will help you. 3388662
Also my code will help you...I think it's simple binary search. 3410336
Look at this one 3390590