日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【HDU - 5012】Dice(模拟,bfs)

發(fā)布時間:2023/12/10 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【HDU - 5012】Dice(模拟,bfs) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

題干:

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,a?2,a?3,a?4,a?5,a?6, representing the numbers on dice A.

The second line consists of six integers b?1,b?2,b?3,b?4,b?5,b?6, 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

題目大意:

給出兩個正方體,每個正方體都有6種顏色,問是否可以經(jīng)過左轉(zhuǎn),右轉(zhuǎn),前轉(zhuǎn),后轉(zhuǎn)四種轉(zhuǎn)法讓兩個正方體看起來一樣(對應面顏色相同),最少轉(zhuǎn)幾次。

解題報告:

?直接bfs。

AC代碼:

#include<cstdio> #include<iostream> #include<algorithm> #include<queue> #include<stack> #include<map> #include<vector> #include<set> #include<string> #include<cmath> #include<cstring> #define FF first #define SS second #define ll long long #define pb push_back #define pm make_pair using namespace std; typedef pair<int,int> PII; const int MAX = 2e5 + 5; vector<int> aa; set<vector<int> > ss; struct Node {vector<int> vv;int s; }; int bfs(vector<int> st) {queue<Node> q;q.push({st,0});while(q.size()) {Node cur = q.front();q.pop();if(cur.vv == aa) return cur.s;if(ss.count(cur.vv)) continue;ss.insert(cur.vv);vector<int> t = cur.vv,nn(6);//Leftnn[0] = t[3],nn[1] = t[2],nn[2] = t[0],nn[3] = t[1],nn[4] = t[4],nn[5] = t[5];q.push({nn,cur.s+1});//Right nn[0] = t[2],nn[1] = t[3],nn[2] = t[1],nn[3] = t[0],nn[4] = t[4],nn[5] = t[5];q.push({nn,cur.s+1});//Frontnn[0] = t[5],nn[1] = t[4],nn[2] = t[2],nn[3] = t[3],nn[4] = t[0],nn[5] = t[1];q.push({nn,cur.s+1});//Backnn[0] = t[4],nn[1] = t[5],nn[2] = t[2],nn[3] = t[3],nn[4] = t[1],nn[5] = t[0];q.push({nn,cur.s+1});}return -1; } int main() {int z,x,c,v,b,n;while(~scanf("%d%d%d%d%d%d",&z,&x,&c,&v,&b,&n)) {aa.clear(); ss.clear();vector<int> a(6);a[0]=z;a[1]=x;a[2]=c;a[3]=v;a[4]=b;a[5]=n;for(int i = 1; i<=6; i++) {scanf("%d",&x);aa.pb(x);}int ans = bfs(a);printf("%d\n",ans);} return 0 ; }

?

總結(jié)

以上是生活随笔為你收集整理的【HDU - 5012】Dice(模拟,bfs)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。