Dice hdu 5012

Problem Description
There are 2 special dices on the table. On each face of the dice, a distinct number was written. Consider a1.a2,a3,a4,a5,a6 to be numbers written on top face, bottom face, left face, right face, front face and back face of dice A. Similarly, consider b1.b2,b3,b4,b5,b6 to be numbers on specific faces of dice B. It’s guaranteed that all numbers written on dices are integers no smaller than 1 and no more than 6 while ai ≠ aj and bi ≠ bj for all i ≠ j. Specially, sum of numbers on opposite faces may not be 7.

At the beginning, the two dices may face different(which means there exist some i, ai ≠ bi). Ddy wants to make the two dices look the same from all directions(which means for all i, ai = bi) only by the following four rotation operations.(Please read the picture for more information)

Now Ddy wants to calculate the minimal steps that he has to take to achieve his goal.

Input
There are multiple test cases. Please process till EOF.

For each case, the first line consists of six integers a1,a2,a3,a4,a5,a6, representing the numbers on dice A.

The second line consists of six integers b1,b2,b3,b4,b5,b6, representing the numbers on dice B.

Output
For each test case, print a line with a number representing the answer. If there’s no way to make two dices exactly the same, output -1.

Sample Input

1 2 3 4 5 6
1 2 3 4 5 6
1 2 3 4 5 6
1 2 5 6 4 3
1 2 3 4 5 6
1 4 2 5 3 6

Sample Output

0
3
-1

Source
2014 ACM/ICPC Asia Regional Xi’an Online


暴力bfs 即可;
这里我们用set 进行判重;

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<deque>
#include<stack>
#include<functional>
#include<sstream>
#include<cctype>
//#pragma GCC optimize("O3")
using namespace std;
#define maxn 200005
#define inf 0x3f3f3f3f
#define INF 0x7fffffff
#define rdint(x) scanf("%d",&x)
#define rdllt(x) scanf("%lld",&x)
typedef long long  ll;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),0,sizeof(x))
const int mod = 1e9 + 7;
#define Mod 20100403
#define sq(x) (x)*(x)
#define eps 1e-10
const int N = 1505;

inline int rd() {
	int x = 0;
	char c = getchar();
	bool f = false;
	while (!isdigit(c)) {
		if (c == '-') f = true;
		c = getchar();
	}
	while (isdigit(c)) {
		x = (x << 1) + (x << 3) + (c ^ 48);
		c = getchar();
	}
	return f ? -x : x;
}

ll gcd(ll a, ll b) {
	return b == 0 ? a : gcd(b, a%b);
}
ll sqr(ll x) { return x * x; }

struct node {
	string s;
	int stp;
};

queue<node>q;
node tmp, tmps;
int num[10];
string a, b;

set<string>st;

int main()
{
	//ios::sync_with_stdio(false);
	while (rdint(num[0]) != EOF) {
	//	a = ""; b = "";
		a = "123456"; b = "123456";
		for (int i = 1; i < 6; i++)rdint(num[i]);
		for (int i = 0; i < 6; i++) {
			a[i] = (char)(num[i] + '0');
			rdint(num[i]);
			b[i] = (char)(num[i] + '0');
		}
		int i, j;
		int fg1=0, fg2;
	//	cout << a << ' ' << b << endl;
		for ( i = 0; i < 6; i+=2) {
			for ( j = 0; j < 6; j += 2) {
				if (a[i] == b[j] && a[i + 1] == b[j + 1] || a[i] == b[j + 1] && a[i + 1] == b[j])
					break;
			}
			if (j >= 6)fg1++;
		}
		if (fg1 == 3) {
			cout << -1 << endl;
		}
		else {
			fg2 = -1; 
			tmp.s = a; tmp.stp = 0;
		//	tmps.s = a; tmps.stp = 0;
			int curans = 0;
			q.push(tmp);
			while (!q.empty()) {
				tmp = q.front(); q.pop();
				if (tmp.s == b) {
					fg2 = tmp.stp;
					break;
				}
				a = tmp.s; curans = tmp.stp;
				// left
				tmp.s[4] = a[4]; tmp.s[5] = a[5];
				tmp.s[0] = a[3]; tmp.s[1] = a[2];
				tmp.s[2] = a[0]; tmp.s[3] = a[1];
				tmp.stp = curans + 1;
				if (st.find(tmp.s) == st.end()) {
					st.insert(tmp.s); q.push(tmp);
				}
				// right 
				tmp.s[4] = a[4]; tmp.s[5] = a[5];
				tmp.s[0] = a[2]; tmp.s[1] = a[3];
				tmp.s[2] = a[1]; tmp.s[3] = a[0];
				tmp.stp = curans + 1;
				if (st.find(tmp.s) == st.end()) {
					st.insert(tmp.s); q.push(tmp);
				}
				// front
				tmp.s[2] = a[2]; tmp.s[3] = a[3];
				tmp.s[0] = a[5]; tmp.s[1] = a[4];
				tmp.s[4] = a[0]; tmp.s[5] = a[1];
				tmp.stp = curans + 1;
				if (st.find(tmp.s) == st.end()) {
					st.insert(tmp.s); q.push(tmp);
				}
				// back 
				tmp.s[2] = a[2]; tmp.s[3] = a[3];
				tmp.s[0] = a[4]; tmp.s[1] = a[5];
				tmp.s[4] = a[1]; tmp.s[5] = a[0];
				tmp.stp = curans + 1;
				if (st.find(tmp.s) == st.end()) {
					st.insert(tmp.s); q.push(tmp);
				}
			}
			if (fg2 != -1) {
				cout << fg2 << endl;
			}
			else cout << -1 << endl;
			while (!q.empty())q.pop();
			st.clear();
		}
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值