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

Автор gatrmani, история, 6 часов назад, По-английски

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?

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

»
6 часов назад, # |
Rev. 2   Проголосовать: нравится +1 Проголосовать: не нравится

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.

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

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

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

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

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

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

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

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

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

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

Print -1 if n<Min else print Min

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

skill issue