/* >>~~ UVa Online Judge ACM Problem Solution ~~<< ID: 10067 Name: Playing with Wheels Problem: https://onlinejudge.org/external/100/10067.pdf Language: C++ Author: Arash Shakery Email: arash.shakery@gmail.com */ #include #include #include #include using namespace std; int readNum(){ int a,b,c,d; cin>>a>>b>>c>>d; return a*1000+b*100+c*10+d; } int rot(int num, int w) { int sgn = w<0?-1:1; w = w<0?-w-1:w-1; int t=1; for (int i=0; i>T; while (T--) { memset(d, 0, sizeof(d)); int s = readNum(), t = readNum(); cin>>n; for (int i=0; i q; q.push(s); while (!q.empty()) { int num = q.front(); q.pop(); int dd = d[num]; if (num == t) { result = dd; break; } if (dd < 0) continue; d[num] = -1; for (int i=-4; i<=4; i++) if(i) { int nn = rot(num, i); if (!d[nn]) { q.push(nn); d[nn] = dd+1; } } } cout << result << endl; } }