题目描述
Eileen has a big luggage and she would pick a lot of things in the luggage every time when A-SOUL goes out for a show. However, if there are too many things in the luggage, the 4-digit password lock on the luggage will be hard to rotate.
The state of lock is the four digits on the lock. In one step, she can choose consecutive digits to rotate up by one simultaneously or down by one simultaneously. For example, she can rotate 0000\texttt{0000}0000 to 0111\texttt{0111}0111 or 0900\texttt{0900}0900 in one step because the rotated digits are consecutive, but she can't rotate 0000\texttt{0000}0000 to 0101\texttt{0101}0101 in one step. Since she has little strength, she wants to rotate the lock as few times as possible.
Now the lock is at state a0a1a2a3a_0a_1a_2a_3a0a1a2a3 and the password is b0b1b2b3b_0b_1b_2b_3b0b1b2b3. As a fan of A-SOUL, you are asked to help Eileen find out the optimal plan to unlock but you only need to tell Eileen how many times she has to rotate.
输入描述:
The first line contains one integer TTT (1≤T≤105)(1 \leq T \leq 10^5)(1≤T≤105), denoting the numer of test cases.
Each of the test cases contains a line containing the initial state a0a1a2a3a_0a_1a_2a_3a0a1a2a3 and the target state b0b1b2b3b_0b_1b_2b_3b0b1b2b3.
输出描述:
For each test case, output a line containing a single integer, denoting the minimum steps needed to unlock.
示例1
输入
6 1234 2345 1234 0123 1234 2267 1234 3401 1234 1344 1234 2468
输出
1 1 4 5 1 4
题意: 有一个4位密码锁,每次操作可以选择其中连续1~4位全部+1或者全部-1,数字在0~9范围内自动取模,求从起始位置转到最终位置需要的最小操作数。
分析: 由于数据规模不大,很容易想到打表,但直接打从起始位置到终点位置的表是不行的,1e8的数据没办法直接放在代码里。这时候考虑终点-起点的每位差值,对于两组测试数据,如果其每位差值相同那么最少操作数也一定相同,因为两组都是把差值转换为0的过程。例如2312 5722和3122 6532,终点状态-起点状态的每位差值都是3 4 1 0,显然都需要4次操作,这时候就可以记录每位差值为3 4 1 0时的答案为4,当再次遇到差为3 4 1 0的数据时直接给出答案4。当然每位作差时会出现负数的情况,例如2312 1111每位作差是-1 -2 0 -1,对于每位作差为负数的情况可以直接加10转为正数,上例中就可以转为9 8 0 9,显然9 8 0 9和-1 -2 0 -1转为0 0 0 0所需要的操作数完全一样。
这样就可以利用bfs打出一个1e4大小的答案数组,直接放代码里实现O(1)调用。
具体代码如下:
#include<iostream>
#include<string>
#include<algorithm>
#include <queue>
#include <cstring>
using namespace std;
int s, e;
int _next[20] = {1, 10, 11, 100, 110, 111, 1000, 1100, 1110, 1111,
-1, -10, -11, -100, -110, -111, -1000, -1100, -1110, -1111};
struct node
{
int num, step;
};
int poww[4] = {1, 10, 100, 1000};
bool vis[10005];
int ans[] = {0,1,2,3,4,5,4,3,2,1,1,1,2,3,4,5,5,4,3,2,2,2,2,3,4,5,6,5,4,3,3,3,3,3,4,5,6,6,5,4,4,4,4,4,4,5,6,6,6,5,5,5,5,5,5,5,5,5,5,5,4,5,6,6,6,5,4,4,4,4,3,4,5,6,6,5,4,3,3,3,2,3,4,5,6,5,4,3,2,2,1,2,3,4,5,5,4,3,2,1,1,2,3,4,5,6,5,4,3,2,1,1,2,3,4,5,5,4,3,2,2,2,2,3,4,5,6,5,4,3,3,3,3,3,4,5,6,6,5,4,4,4,4,4,4,5,6,7,6,5,5,5,5,5,5,5,6,6,6,6,5,6,6,6,6,6,5,5,5,5,4,5,6,7,7,6,5,4,4,4,3,4,5,6,7,6,5,4,3,3,2,3,4,5,6,6,5,4,3,2,2,3,4,5,6,7,6,5,4,3,2,2,3,4,5,6,6,5,4,3,2,2,2,3,4,5,6,5,4,3,3,3,3,3,4,5,6,6,5,4,4,4,4,4,4,5,6,7,6,5,5,5,5,5,5,5,6,7,7,6,6,6,6,6,6,6,6,6,6,6,5,6,7,7,7,7,6,5,5,5,4,5,6,7,8,7,6,5,4,4,3,4,5,6,7,7,6,5,4,3,3,4,5,6,7,8,7,6,5,4,3,3,4,5,6,7,7,6,5,4,3,3,3,4,5,6,7,6,5,4,3,3,3,3,4,5,6,6,5,4,4,4,4,4,4,5,6,7,6,5,5,5,5,5,5,5,6,7,7,6,6,6,6,6,6,6,6,7,7,7,6,7,7,7,7,7,7,6,6,6,5,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7,6,5,4,5,6,7,8,9,8,7,6,5,5,5,6,7,8,9,9,8,7,6,6,6,6,7,8,8,8,8,8,7,7,7,7,7,7,7,7,7,7,7,6,7,7,7,6,6,6,6,6,6,5,6,7,7,6,5,5,5,5,5,4,5,6,7,6,5,4,4,4,4,4,5,6,7,7,6,5,4,4,4,4,5,6,7,8,7,6,5,4,4,4,5,6,7,8,8,7,6,5,4,3,4,5,6,7,8,7,6,5,4,4,4,5,6,7,8,8,7,6,5,5,5,5,6,7,8,8,8,7,6,6,6,6,6,7,7,7,7,7,7,6,7,7,7,6,6,6,6,6,6,5,6,7,7,6,5,5,5,5,5,4,5,6,7,6,5,4,4,4,4,3,4,5,6,6,5,4,3,3,3,3,4,5,6,7,6,5,4,3,3,3,4,5,6,7,7,6,5,4,3,2,3,4,5,6,7,6,5,4,3,3,3,4,5,6,7,7,6,5,4,4,4,4,5,6,7,8,7,6,5,5,5,5,5,6,7,7,7,7,6,6,6,6,6,6,6,6,6,6,6,5,6,7,7,6,5,5,5,5,5,4,5,6,7,6,5,4,4,4,4,3,4,5,6,6,5,4,3,3,3,2,3,4,5,6,5,4,3,2,2,2,3,4,5,6,6,5,4,3,2,1,2,3,4,5,6,5,4,3,2,2,2,3,4,5,6,6,5,4,3,3,3,3,4,5,6,7,6,5,4,4,4,4,4,5,6,7,7,6,5,5,5,5,5,5,6,6,6,6,6,5,6,6,6,6,5,5,5,5,5,4,5,6,7,6,5,4,4,4,4,3,4,5,6,6,5,4,3,3,3,2,3,4,5,6,5,4,3,2,2,1,2,3,4,5,5,4,3,2,1};
//void bfs()
//{
// queue<node> q;
// q.push({s, 0});
// while(q.size())
// {
// node now = q.front();
// q.pop();
// if(now.num == e)
// {
// ans = now.step;
// return;
// }
// for(int i = 0; i < 20; i++)
// {
// int num[4];
// int tt = now.num;
// int t = _next[i];
// for(int i = 0; i <= 3; i++)
// {
// num[i] = tt%10;
// tt /= 10;
// }
// if(t < 0)
// {
// t = -t;
// for(int i = 0; i <= 3; i++)
// {
// num[i] = (num[i]-t%10+10)%10;
// t /= 10;
// }
// }
// else
// {
// for(int i = 0; i <= 3; i++)
// {
// num[i] = (num[i]+t%10)%10;
// t /= 10;
// }
// }
// int ne = 0;
// for(int i = 0; i <= 3; i++)
// ne += num[i]*pow(10, i);
// if(!vis[ne])
// {
// vis[ne] = true;
// q.push({ne, now.step+1});
// }
// }
// }
//}
signed main()
{
int T;
cin >> T;
while(T--)
{
scanf("%d%d", &s, &e);
// s = 0;
// for(int i = 1; i <= 9999; i++)
// {
// e = i;
// memset(vis, 0, sizeof vis);
// bfs();
// printf("%d,", ans);
// }
int snum[4], rnum[4], a[4];
for(int i = 0; i <= 3; i++)
{
snum[i] = s%10;
s /= 10;
rnum[i] = e%10;
e /= 10;
a[i] = (rnum[i]-snum[i]+10)%10;
}
int res = 0;
for(int i = 0; i <= 3; i++)
res += a[i]*poww[i];
printf("%d\n", ans[res]);
}
return 0;
}