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

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

I've seen most programmers, when they declare an array globally, they take some extra spaces. for example, if the question asks for a 10^7 sized array they declare like this :

const int N = 1e7+10
int a[N]

why 10 extra spaces?

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

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

When you do some operations on arrays which involve complicated indices (such as DP recursions), you can and often will access some index that is beyond $$$n$$$, such as $$$n+1$$$ or $$$n+2$$$. Usually it's just quicker to just add an arbitrary +5 or +10 than to calculate the exact number of extra spaces you need in the array.

(I personally don't do this +5/+10 thing, because I feel that this makes me lazy in thinking, but oh well, lots of people are doing it and they're just fine.)

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

it just feels good

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

It gives you +10 extra CF rating