设为首页 加入收藏

TOP

hdu5012 Dice(bfs)
2015-07-20 17:41:19 来源: 作者: 【 】 浏览:2
Tags:hdu5012 Dice bfs

题目链接:

点我点我

思路:主要是状态我没想到怎么表示,后来看的队友的,毕竟自己太弱。

题目:

Dice

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


Problem Description There are 2 special dices on the table. On each face of the dice, a distinct number was written. Consider a 1.a 2,a 3,a 4,a 5,a 6 to be numbers written on top face, bottom face, left face, right face, front face and back face of dice A. Similarly, consider b 1.b 2,b 3,b 4,b 5,b 6 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 a i ≠ a j and b i ≠ b j 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, a i ≠ b i). Ddy wants to make the two dices look the same from all directions(which means for all i, a i = b i) 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 a 1<??http://www.2cto.com/kf/ware/vc/" target="_blank" class="keylink">vc3ViPixhPHN1Yj4yPC9zdWI+LGE8c3ViPjM8L3N1Yj4sYTxzdWI+NDwvc3ViPixhPHN1Yj41PC9zdWI+LGE8c3ViPjY8L3N1Yj4sIHJlcHJlc2VudGluZyB0aGUgbnVtYmVycyBvbiBkaWNlIEEuIDxicj4KPGJyPgpUaGUgc2Vjb25kIGxpbmUgY29uc2lzdHMgb2Ygc2l4IGludGVnZXJzIGI8c3ViPjE8L3N1Yj4sYjxzdWI+Mjwvc3ViPixiPHN1Yj4zPC9zdWI+LGI8c3ViPjQ8L3N1Yj4sYjxzdWI+NTwvc3ViPixiPHN1Yj42PC9zdWI+LCByZXByZXNlbnRpbmcgdGhlIG51bWJlcnMgb24gZGljZSBCLgoKIAo8YnI+CgpPdXRwdXQKCkZvciBlYWNoIHRlc3QgY2FzZSwgcHJpbnQgYSBsaW5lIHdpdGggYSBudW1iZXIgcmVwcmVzZW50aW5nIHRoZSBhbnN3ZXIuIElmIHRoZXJloa9zIG5vIHdheSB0byBtYWtlIHR3byBkaWNlcyBleGFjdGx5IHRoZSBzYW1lLCBvdXRwdXQgLTEuCgogCjxicj4KClNhbXBsZSBJbnB1dAoKPHByZSBjbGFzcz0="brush:java;">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
Recommend hujie | We have carefully selected several similar problems for you: 5017 5016 5015 5014 5013 代码:
#include
   
    
#include
    
      #include
     
       #include
      
        #include
        #include
        
          #include
         
           #include
          
            #include
           
             #define eps 1e-9 #define ll long long #define INF 0x3f3f3f3f using namespace std; const int maxn=999999+10; struct cube { int a1,a2,a3,a4,a5,a6; int key; }st,en,next; queue
            
             Q; int ans; bool vis[maxn]; int gao(cube c) { int temp=0; temp+=c.a1*1; temp+=c.a2*10; temp+=c.a3*100; temp+=c.a4*1000; temp+=c.a5*10000; temp+=c.a6*100000; return temp; } cube solve(cube c,int k) { cube temp; if(k==1) { temp.a1=c.a4; temp.a2=c.a3; temp.a3=c.a1; temp.a4=c.a2; temp.a5=c.a5; temp.a6=c.a6; } else if(k==2) { temp.a1=c.a3; temp.a2=c.a4; temp.a3=c.a2; temp.a4=c.a1; temp.a5=c.a5; temp.a6=c.a6; } else if(k==3) { temp.a1=c.a6; temp.a2=c.a5; temp.a3=c.a3; temp.a4=c.a4; temp.a5=c.a1; temp.a6=c.a2; } else { temp.a1=c.a5; temp.a2=c.a6; temp.a3=c.a3; temp.a4=c.a4; temp.a5=c.a2; temp.a6=c.a1; } return temp; } int bfs() { ans=gao(en); memset(vis,false,sizeof(vis)); while(!Q.empty()) Q.pop(); st.key=0; Q.push(st); int temp=gao(st); vis[temp]=true; while(!Q.empty()) { cube current=Q.front(); Q.pop(); if(ans==gao(current)) return current.key; for(int i=1;i<=4;i++) { next=solve(current,i); next.key=current.key+1; int temp=gao(next); if(!vis[temp]) { vis[temp]=true; Q.push(next); } } } return -1; } int main() { while(~scanf("%d",&st.a1)) { scanf("%d%d%d%d%d",&st.a2,&st.a3,&st.a4,&st.a5,&st.a6); scanf("%d%d%d%d%d%d",&en.a1,&en.a2,&en.a3,&en.a4,&en.a5,&en.a6); printf("%d\n",bfs()); } return 0; } 
            
           
          
         
        
      
     
    
   



】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇hdu 1009 233 Matrix 矩阵构造 --.. 下一篇HDU 2147 kiki's game(巴什博..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·用 C 语言或者限制使 (2025-12-25 08:50:05)
·C++构造shared_ptr为 (2025-12-25 08:50:01)
·既然引用计数在做 GC (2025-12-25 08:49:59)
·Java 编程和 c 语言 (2025-12-25 08:19:48)
·. net内存管理宝典这 (2025-12-25 08:19:46)