sci4me

grid compression

Jun 2nd, 2018 (edited)
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. Given some n by m grid, we want to convert it into a "compressed" representation. Example:
  2.  
  3. 1 0 1 2 1
  4. 0 0 1 2 0
  5. 0 0 1 3 0
  6. 0 1 1 2 0
  7. 0 1 0 2 0
  8.  
  9. would be represented as:
  10.  
  11. Set(0, 0, 1)
  12. Fill(1, 0, 1, 2, 0)
  13. Fill(2, 0, 2, 3, 1)
  14. Fill(2, 0, 2, 1, 2)
  15.  
  16. etc.
  17.  
  18. Of course there are sub-optimal solutions to this problem, and probably (I'm guessing) in some cases, multiple optimal solutions as well.
  19. What's an algorithm that could solve this? And how fast is said algorithm? Better than O(n^2)?
Add Comment
Please, Sign In to add comment