gatrmani's blog

By gatrmani, history, 3 hours ago, In English

guys i need help on this problem: https://codeforces.me/contest/2072/problem/A

can someone tell me how to start i am very confused, do i need to know DFS for this?

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
3 hours ago, # |
Rev. 2   Vote: I like it +1 Vote: I do not like it

No, you don't need DFS for this problem.

For this kind of question, first try searching for a solution on the internet. If you still can't find a good one, then ask here.

  • »
    »
    3 hours ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    sorry man usually i solve question a but this time the question makers gave bad one

»
3 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

this is pure adhoc, you gotta make sure that abs(k) is smaller than or equal to n*p, if not then it is impossible, else just cout k/p (you will need to add 1 if k is not divisible by p).

  • »
    »
    3 hours ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    thanks but what is adhoc? can you write adhoc alogrithm in c++ here for me because i still don't get it.

    • »
      »
      »
      3 hours ago, # ^ |
      Rev. 3   Vote: I like it 0 Vote: I do not like it

      in short, adhoc problems have no standard way to solve, it is just like trying to capture a pattern for the problem, there is no way to standardize adhoc problems, you just get better with time.

      for this problem a solution will be smthin like this:

      k = abs(k);

      if (k > n*p) cout << -1 << '\n';

      else cout << (k/p) + (1*(k%p!=0)) << '\n';

»
3 hours ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

Min=abs(k)//p if abs(k)%p==0 else Min=abs(k)//p+1

Print -1 if n<Min else print Min

  • »
    »
    86 minutes ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    You can do this .It's way simpler

    Min=(abs(k)+p-1)//p

»
3 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

skill issue