Minimum steps to set a series of rotating dials to a given sequence

假如想象 提交于 2019-12-02 21:22:59

I'm not sure if I understand correctly the problem. It seems that if you rotate two numbers together 1 step, that move is counted only as one move, not two, correct?

In that case why not count the minimum distance between every number and its match in the other series. After that group together minus moves and plus moves, and move the numbers together where possible.

Ex:

145 -> 632

  • 1 has min distance 5+- (up or down)
  • 4 has min distance 1-
  • 5 has min distance 3-

Since there only are minus moves, I would count the 5 also as a minus move, and do following:

  1. move all numbers down one step -> 034
  2. move first and last number down two steps -> 832
  3. move last number down two steps -> 632 = total 5 steps
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!