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

Автор muhammadhasan01, 2 года назад, По-английски

Invariant is a property that remains unchanged after operations/transformation, we see this a lot in competitive programming, especially with operations involved.

Simple Example

I wanted to make an "Invariant List" here so the community could benefit from it, if you have some invariants in mind share with us in the comment below, or you could also share some tips/insights to find invariants effectively.

I'd like to share some interesting invariants myself here, I've found these in some online judges, but I won't discuss too much of the detail for the solution/proof.


Problem 1

Problem 2

Problem 3

Problem 4

Problem 5

Problem 6

Problem 7

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

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

These problems pop into my mind when talking about invariants in competitive programming. They are quite similar.

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

If I understand your solution to problem 2 correctly, I think you should specify that you are considering each bit separately.

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

One that's appeared many times are variations on 1025C - Plasticine zebra.

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

Easy invariants problem for matrices https://codeforces.me/problemset/problem/1980/E.

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

Just curious: For state set $$$S$$$ and transition set $$$T$$$, what do we call function $$$f$$$ if the following condition hold? The largest invariant?

$$$(s_1, s_2) \in T \iff f(s_1) = f(s_2)$$$

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

    I know it's a bit late, but $$$T$$$ is called the (set-theoretic) kernel of $$$f$$$; $$$f$$$ itself doesn't really have a name as this can be defined for any function. More about this can be found here.

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

bump, last div2 D (2252D - Array Replacement) is very similar to problem 4 here,

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

there is an array of length N and N persons that are on each position. In each query, the persons on the cells with value X moves left or right (to the previous/next cell); if they move out of bounds, they become unchanged after. Find the total number of out of bound positions after all queries.

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

    I don't think this holds. Lets say wlog we take a person who starts at cell 3, we then move all people on cell 3 right. Person is on cell 4, we then query cell 4 left and that person is on cell 3. Thus the cell that person is on is not monotonic since it can increase and decrease. I think the number of out of bounds positions is monotonic at all times?

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

problem 5 reminds me of High Templars.

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

can someone suggest a good maths book or any other resoruce conatining invariant problems