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

Автор ayush29azad, история, 3 года назад, По-английски

How to solve this problem using bitmask or bit manuplation ??

Problem Link :https://codeforces.me/problemset/problem/1097/B Editorial Link :https://codeforces.me/blog/entry/64310

I am not able to understand the editorial which says that clockwise rotation will be done if ith bit is set to 0 and vive versa ?? Can someone explain in detail ?

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

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

Every rotation can be represented as 0 — clockwise or 1 — counterclockwise. It means that if you have to do N rotations, than you can represent all possible ways of rotations by 2 ^ N bit strings. For example for N = 2 you have 4 states — 00, 01, 10, 11. Than just check each state (iterate throw bit string, if bit is 1 — add angle, else — substract) if angle is divisible by 360, you found solution.