Go through all the overmasks

Правка en1, от rembocoder, 2020-02-11 20:35:00

In this thread is shown how to go though all the submasks of a given mask without extra space or time. I needed to do the same thing for the overmasks, but I did not find anything. Based on the formula mask ^ (~mask) = -1, my brother gave me this code:

    for (int over = (1 << n) - 1; over > 0; over = ((over - mask - 1) & ~mask) + mask) {
        cout << over << " ";
    }

It really works. But can I simplify it, so it could be easier remembered during the contest?

Теги submasks, overmasks, over-masks, masks, bitmasks

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en3 Английский rembocoder 2020-10-26 23:42:03 5
en2 Английский rembocoder 2020-02-11 20:38:05 3 Tiny change: ') thread is shown ' -> ') thread it is shown ' (published)
ru3 Русский rembocoder 2020-02-11 20:36:28 0 (опубликовано)
en1 Английский rembocoder 2020-02-11 20:35:00 574 Initial revision for English translation (saved to drafts)
ru2 Русский rembocoder 2020-02-11 20:31:19 15 Мелкая правка: 'в [этой](ht' -> 'В [этой](ht'
ru1 Русский rembocoder 2020-02-11 20:28:40 597 Первая редакция (сохранено в черновиках)