How can this problem be solved by mathematically ??? Help please ...
I've tried seeing others code,but failed to understand... :(
problem link ... Here
# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 150 |
How can this problem be solved by mathematically ??? Help please ...
I've tried seeing others code,but failed to understand... :(
problem link ... Here
Name |
---|
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