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