Dice
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1109 Accepted Submission(s): 584
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.
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.
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
题意:
给出两个骰子 A 和 B,分别给出六个面的数字,有向左转,向右转,向前转,向后转四种操作,问最少几步能转到相同,输出步数,如果无论如何都不可能则输出 -1。
思路:
BFS。表示出 4 种转的状态即可,白痴错误 WA 了两次。
AC:
#include <cstdio> #include <cstring> #include <algorithm> #include <queue> using namespace std; typedef struct { int ans[10]; int step, l_t, r_t, b_t, f_t; } state; int fin[10], num[10]; void Left (int *a) { int b[10]; for (int i = 1; i <= 6; ++i) { b[i] = a[i]; } a[1] = b[4], a[2] = b[3], a[3] = b[1]; a[4] = b[2], a[5] = b[5], a[6] = b[6]; } void Right (int *a) { int b[10]; for (int i = 1; i <= 6; ++i) { b[i] = a[i]; } a[1] = b[3], a[2] = b[4], a[3] = b[2]; a[4] = b[1], a[5] = b[5], a[6] = b[6]; } void Front (int *a) { int b[10]; for (int i = 1; i <= 6; ++i) { b[i] = a[i]; } a[1] = b[6], a[2] = b[5], a[3] = b[3]; a[4] = b[4], a[5] = b[1], a[6] = b[2]; } void Back (int *a) { int b[10]; for (int i = 1; i <= 6; ++i) { b[i] = a[i]; } a[1] = b[5], a[2] = b[6], a[3] = b[3]; a[4] = b[4], a[5] = b[2], a[6] = b[1]; } bool test1 () { int tt[10][10]; memset(tt, 0, sizeof(tt)); for (int i = 2; i <= 6; i += 2) { tt[ num[i - 1] ][ num[i] ] = 1; tt[ num[i] ][ num[i - 1] ] = 1; } for (int i = 2; i <= 6; i += 2) { if (!tt[ fin[i - 1] ][ fin[i] ]) return false; if (!tt[ fin[i] ][ fin[i - 1] ]) return false; } return true; } bool test2 (int *a) { for (int i = 1; i <= 6; ++i) { if (a[i] != fin[i]) return false; } return true; } int bfs () { state a; for (int i = 1; i <= 6; ++i) { a.ans[i] = num[i]; } a.l_t = a.r_t = a.f_t = a.b_t = 0; a.step = 0; queue<state> q; q.push(a); while (!q.empty()) { state now = q.front(); q.pop(); if (test2(now.ans)) return now.step; state b; b.step = now.step + 1; if (now.l_t < 3) { for (int i = 1; i <= 6; ++i) { b.ans[i] = now.ans[i]; } Left(b.ans); b.b_t = now.b_t; b.f_t = now.f_t; b.r_t = now.r_t; b.l_t = now.l_t + 1; q.push(b); } if (now.r_t < 3) { for (int i = 1; i <= 6; ++i) { b.ans[i] = now.ans[i]; } Right(b.ans); b.l_t = now.l_t; b.b_t = now.b_t; b.f_t = now.f_t; b.r_t = now.r_t + 1; q.push(b); } if (now.f_t < 3) { for (int i = 1; i <= 6; ++i) { b.ans[i] = now.ans[i]; } Front(b.ans); b.b_t = now.b_t; b.l_t = now.l_t; b.r_t = now.r_t; b.f_t = now.f_t + 1; q.push(b); } if (now.b_t < 3) { for (int i = 1; i <= 6; ++i) { b.ans[i] = now.ans[i]; } Back(b.ans); b.l_t = now.l_t; b.f_t = now.f_t; b.r_t = now.r_t; b.b_t = now.b_t + 1; q.push(b); } } return -1; } int main() { while (~scanf("%d", &num[1])) { for (int i = 2; i <= 6; ++i) scanf("%d", &num[i]); for (int i = 1; i <= 6; ++i) scanf("%d", &fin[i]); if (!test1()) printf("-1\n"); else printf("%d\n", bfs()); } return 0; }
相关推荐
DICe是一个开源的数字图像相关(DIC)工具,用于外部应用程序中的模块或作为独立的分析代码使用。它的主要功能是从数字图像序列中计算全场位移和应变,以及物体的刚体运动跟踪。所分析的图像通常是一个正在进行特征...
本资源包含基于Matlab的使用dice相似系数方法进行图像分割精度验证源码和图片素材。 包含 实例1:计算二值分割图像的dice相似系数 实例2:计算多区域分割图像的dice相似系数 本资源配套CSDN博客“Matlab图像分割---...
之前在文章:https://blog.csdn.net/Sweety_Lin/article/details/104199580 中写的DICE计算程序,是将Nii的整个volume计算在内,现想提取T2中有lesion的特定层面来计算DICE: import nibabel as nib import scipy....
1.版本:matlab2019a,不会运行可私信 2.领域:基础教程 3.内容:【数据分析】MATLAB计算dice系数.zip 4.适合人群:本科,硕士等教研学习使用
一个简单的骰子滚动应用程序演示了一个多平台的功能架构,前端用于android和ios。
实用的仿真系统DICE-51 单片机学习者可以多加关注啊
vhdl语言小程序dicegame 即骰子游戏,根据已经有的规则完成的程序,编译仿真通过
DICE-5210k用户手册20100606
Dice-game-源码.rar
Dice Game - Android Studio is the source code which ready to build and run.
VIDA2013A DICE VOLVO 种子下载 VIDA2012D VIDA2012C 升级版
matlab开发-DiceGame。玩一个有趣又容易学的骰子游戏。独自一人,和朋友在一起,或者和不同技能水平的人工智能作比较。
Dice播放器 DicePlayer 版本:2.0.54 大小:13 MB 适用固件:Android 2.2.X及以上 分享日期:2014-04-04 游戏题材:视频 开发商:INISOFT_DEV 内容介绍 DicePlayer是一款高性能播放器,基于硬件加速播放。HTC ...
本系统使用DICE—8086K实验箱,采用8253的定时功能,8259的中断处理,数码管显示,用汇编语言设计。 利用8253产生2Hz的方波:因为实验板只能产生1.8432MHz的信号,而一个计数器最大计数值为65536Hz,要产生2Hz的方波...
DICE-E213实验指导书20140814EP4CE6E22C8N核心卡说明文档。很全面很不错
DICE-5208K 新型单片机综合实验仪
图像分割评测指标,dice,voe,ASD,RVD等,适用于2d分割图像或者3d图像分割
针对协同过滤算法中项目(用户)之间的相似度计算出现的部分项目的相似度无法计算、对稀疏数据效果较差等问题,提出了一种计算项目之间相似度的新算法——Dice-Euclidean相似度算法。该算法综合考虑两个项目的共同...
单片机,,dice-51仿真开发系统。 离我们五彩的生活又近了一步!!!
DICE2013模型翻译1.pdf