How to solve spoj CLEVER?

Правка en2, от rebornplusplus, 2018-07-03 10:37:36

How to solve spoj's CLEVER ?
( Problem statement given below )

CLEVER — The Clever Typist
no tags 
Time limit:	1s 

Blue Mary is a typist of some secret department.Now she has to type in many passwords in an hour,each of which has a fixed length: 6.Of course,the less times she presses the keyboard,the happier she is.

Unfortunately,the keyboard to type in the password is extraordinary designed to keep secrets.The keyboard has 6 particular keys instead of 10 number keys.To explain the usages of these keys,let's define the 6 position on the screen 1,2,3,4,5,6 from left to right.The keys' usages are shown below:

    Swap0: swap the digit in the cursor position and the digit in position 1.The cursor doesn't move.If the cursor is now in position 1,the digits on the screen won't be changed.
    Swap1: swap the digit in the cursor position and the digit in position 6.The cursor doesn't move.If the cursor is now in position 6,the digits on the screen won't be changed.
    Up: increase the digit in the cursor position by 1.If the digit in the cursor position is 9,no change will happen.
    Down: decrease the digit in the cursor position by 1.If the digit in the cursor position is 0,no change will happen.
    Left: move the cursor one position left.If the cursor is in position 1,no change will happen.
    Right: move the cursor one position right.If the cursor is in position 6,no change will happen.

At start,6 random digits will be given on the screen,and the cursor will in position 1.After some smart presses,she can type in the correct password,at that time the cursor position is unimportant.

Here is an example("()"denotes to the cursor):

key pressed       screen
                  (1)23456
Swap1             (6)23451
Right             6(2)3451
Swap0             2(6)3451
Down              2(5)3451
Right             25(3)451
Up                25(4)451
Right             254(4)51
Down              254(3)51
Right             2543(5)1
Up                2543(6)1
Swap0             6543(2)1

Now Mary wants to know the minimal number of keys she has to press.Can you help her?
Input

The first line contains a single integer t(about 1000).t lines follow,each contains two 6-digit string,which show the digits on the screen at start and the password Mary is to type in,separated by a single space.
Output

t lines,each contains a single integer — the answer.
Example

Sample input:
1
123456 654321

Sample output:
11
Теги spoj

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en3 Английский rebornplusplus 2018-07-03 10:39:54 43 (published)
en2 Английский rebornplusplus 2018-07-03 10:37:36 50 Tiny change: 'EVER/) ?\n\n<pre s' -> 'EVER/) ?\n( Problem statement given below )\n\n<pre s'
en1 Английский rebornplusplus 2018-07-02 00:36:13 2567 Initial revision (saved to drafts)