Блог пользователя shashiHIGS

Автор shashiHIGS, 11 лет назад, По-английски

Can anyone help me to improve the code.. Here is my solution:3406918.

  • Проголосовать: нравится
  • +2
  • Проголосовать: не нравится

»
11 лет назад, # |
  Проголосовать: нравится +6 Проголосовать: не нравится

you should use binary search

»
11 лет назад, # |
Rev. 2   Проголосовать: нравится -8 Проголосовать: не нравится

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

  • »
    »
    11 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    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)) ---> Why we must change this?Does it make our time less?

    • »
      »
      »
      11 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      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.

    • »
      »
      »
      11 лет назад, # ^ |
      Rev. 5   Проголосовать: нравится 0 Проголосовать: не нравится

      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'...