Dice

http://acm.hdu.edu.cn/showproblem.php?pid=5012

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2352    Accepted Submission(s): 1178

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
 
模拟搜索水题
 #include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstdio>
#include<queue>
#include<map>
#include<vector>
typedef long long ll;
#define maxn 100005
using namespace std; int a[],b[];
map<int,int>mp;
struct sair{
int num,step;
}; sair Roll(sair tmp,int x){
//左右前后
sair ans;
ans.num=;
int aa[];
int xx=tmp.num;
for(int i=;i>=;i--){
a[i]=xx%;
xx/=;
}
if(x==){
ans.num=ans.num*+a[];
ans.num=ans.num*+a[];
ans.num=ans.num*+a[];
ans.num=ans.num*+a[];
ans.num=ans.num*+a[];
ans.num=ans.num*+a[];
}
else if(x==){
ans.num=ans.num*+a[];
ans.num=ans.num*+a[];
ans.num=ans.num*+a[];
ans.num=ans.num*+a[];
ans.num=ans.num*+a[];
ans.num=ans.num*+a[];
}
else if(x==){
ans.num=ans.num*+a[];
ans.num=ans.num*+a[];
ans.num=ans.num*+a[];
ans.num=ans.num*+a[];
ans.num=ans.num*+a[];
ans.num=ans.num*+a[];
}
else{
ans.num=ans.num*+a[];
ans.num=ans.num*+a[];
ans.num=ans.num*+a[];
ans.num=ans.num*+a[];
ans.num=ans.num*+a[];
ans.num=ans.num*+a[];
}
ans.step=tmp.step+;
return ans;
} void bfs(int S,int E){
sair s,e;
if(S==E){
cout<<<<endl;
return;
}
s.num=S,s.step=;
queue<sair>Q;
Q.push(s);
while(!Q.empty()){
s=Q.front();
Q.pop();
for(int i=;i<;i++){
e=Roll(s,i);
if(e.num==E){
cout<<e.step<<endl;
return;
}
if(!mp[e.num]){
Q.push(e);
mp[e.num]=;
}
}
}
cout<<-<<endl;
} int main(){
while(cin>>a[]){
mp.clear();
for(int i=;i<=;i++) cin>>a[i];
int S=,E=;
for(int i=;i<=;i++) E=E*+a[i];
for(int i=;i<=;i++) cin>>b[i];
for(int i=;i<=;i++) S=S*+b[i];
bfs(S,E);
}
}

最新文章

  1. PHP如何通过Http Post请求发送Json对象数据?
  2. 开发基础框架:mybatis-3.2.8 +hibernate4.0+spring3.0+struts2.3
  3. 关于线程池ThreadPoolExecutor使用总结
  4. Struts2初学习记录
  5. PreparedStatement与Statement
  6. c++类的声明
  7. LFYZ-OJ ID: 1024 火车站
  8. 【雷神源码解析】无基础看懂AAC码流解析,看不懂你打我
  9. Js 转动抽奖实现
  10. 关于Mui严格模式下的报错解决方案
  11. 【python小练】0012题
  12. c# 调apicontroller
  13. centos6.5环境下svn服务器和客户端配置实用详解
  14. gitlab不小心把sign-in取消了怎么恢复
  15. chmod修改权限
  16. js之function
  17. py-faster-rcnn在windows下安装
  18. Lora通讯
  19. oracle 快速批量插入复杂数据的内容
  20. Data striping

热门文章

  1. 利用ubuntu的alias命令来简化许多复杂难打的命令
  2. ossfs工具将OSS挂载到阿里云linux系统目录例子
  3. java.lang.Object类
  4. 与PHP5.3.5的战斗----记php5.3.5安装过程
  5. pandas的to_csv函数
  6. Vue 组件以及生命周期函数
  7. C++ 无锁队列实现
  8. HTML(具体代码看笔记本)
  9. tornado-模板,转义,上传静态文件
  10. 好久没玩laravel了,5.6玩下(一)