Can anyone help me to improve the code.. Here is my solution:3406918.
# | User | Rating |
---|---|---|
1 | tourist | 3690 |
2 | jiangly | 3647 |
3 | Benq | 3581 |
4 | orzdevinwang | 3570 |
5 | Geothermal | 3569 |
5 | cnnfls_csy | 3569 |
7 | Radewoosh | 3509 |
8 | ecnerwala | 3486 |
9 | jqdai0815 | 3474 |
10 | gyh20 | 3447 |
# | User | Contrib. |
---|---|---|
1 | maomao90 | 173 |
2 | awoo | 164 |
3 | adamant | 163 |
4 | TheScrasse | 159 |
5 | nor | 157 |
6 | maroonrk | 156 |
7 | -is-this-fft- | 152 |
8 | Petr | 146 |
8 | orz | 146 |
10 | pajenegod | 145 |
Can anyone help me to improve the code.. Here is my solution:3406918.
Name |
---|
you should use binary search
Use scanf()/printf()
And also change this part
for(long long i=K;i<N;i+=(K-T-1))
to long long i; for(i=K;i<N;i+=(K-T-1))*** Brute force is the alternate solution of this problem ... But actually this problem should be done by binary search or mathematically
And also change this part
for(long long i=K;i<N;i+=(K-T-1))
tolong long i; for(i=K;i<N;i+=(K-T-1))
---> Why we must change this?Does it make our time less?No it doesn't make the time less. Your algorithm is still O(N) which is not fast enough. Binary Search (O(lgN)) does the work! The idea is that if you know that you need x splitters, the greedy way is to pick the x splitters that have the most outputs (the last splitter mightn't be in these top x splitters to have n outputs in total), so basically you bsearch to find x.
Suhaylee, You can read comments of this entry... here you will see a comment just like this post... from that, I have made me known that, it makes our time less...
this solution gives TLE, where as this is accepted ... difference is in just data type of 'i'... And you may know, 'long long' takes some more time than 'int'...