`
Simone_chou
  • 浏览: 195710 次
  • 性别: Icon_minigender_2
  • 来自: 广州
社区版块
存档分类
最新评论

Dice(BFS)

    博客分类:
  • HDOJ
 
阅读更多

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.
 

 

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

 

      题意:

      给出两个骰子 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-2.0-beta.16_dic_dice_DICe数字图像_DICe图像_数字图像DIC_

    DICe是一个开源的数字图像相关(DIC)工具,用于外部应用程序中的模块或作为独立的分析代码使用。它的主要功能是从数字图像序列中计算全场位移和应变,以及物体的刚体运动跟踪。所分析的图像通常是一个正在进行特征...

    dice,.zip

    标题中的“dice.zip”指的是一个压缩文件,其中包含了一个名为“dice”的开源项目。这个项目是一个简单的骰子滚动应用,它的设计目标是实现跨平台功能,可以在Android和iOS这两种主流移动操作系统上运行。 首先,...

    基于Matlab的使用dice相似系数方法进行图像分割精度验证.txt

    本资源包含基于Matlab的使用dice相似系数方法进行图像分割精度验证源码和图片素材。 包含 实例1:计算二值分割图像的dice相似系数 实例2:计算多区域分割图像的dice相似系数 本资源配套CSDN博客“Matlab图像分割---...

    dice51开发系统EXE

    《DICE-51开发系统EXE:单片机学习者的实用工具》 在电子工程领域,单片机的学习和应用是不可或缺的一部分。对于初学者和专业人士来说,拥有一款功能强大、操作简便的仿真系统至关重要。DICE-51(Digital ...

    利用 python/keras/tensorflow 计算 DICE系数,评估 3D 分割结果,只挑选特定层面

    之前在文章:https://blog.csdn.net/Sweety_Lin/article/details/104199580 中写的DICE计算程序,是将Nii的整个volume计算在内,现想提取T2中有lesion的特定层面来计算DICE: import nibabel as nib import scipy....

    Python库 | dice_ml-0.2.tar.gz

    Python库dice_ml是用于机器学习模型解释性的一种工具,它为数据科学家和机器学习工程师提供了一个易用的接口,以理解黑盒模型的预测行为。这个库的核心目标是提高模型的透明度,使得非技术人员也能理解模型的工作...

    数据分析MATLAB计算dice系数.zip

    dice系数,又称Sørensen-Dice系数,是衡量两个集合相似度的一种指标,广泛应用于图像分析、医学影像处理和自然语言处理等领域。在MATLAB中,计算dice系数可以帮助我们评估分类或分割结果的准确性。本教程将详细介绍...

    DICE2013模型翻译1.pdf

    DICE2013模型翻译1.pdf DICE2013 模型是气候变化经济学的综合评估模型(IAM),它是一个动态的分析与实证模型,用于代表气候变化的经济、政策和科学方面。该模型是全球性的汇总模型,旨在讨论气候变化对经济的影响...

    Dice Game - Android Studio

    【Dice Game - Android Studio】是一款基于Android Studio开发的骰子游戏源代码,它为开发者提供了一个现成的项目模板,可以直接构建和运行。这个项目涵盖了Android应用开发的基础知识,包括UI设计、事件处理、...

    VIDA2013A DICE 最新版本

    VIDA2013A DICE VOLVO 种子下载 VIDA2012D VIDA2012C 升级版

    利用py文件计算多类别的nii.gz 3d数据的dice指标

    利用py文件计算多类别的nii.gz 3d数据的dice指标,传入预测的nii数据和真实的gt nii数据,即可进行多类别的dice计算。 代码会返回一个数组,每个值就是对应类别的dice值,以及最后生成的mean dice

    DICE-5210k用户手册20100606.pdf

    ### DICE-5210K单片机实验开发系统详解 #### 一、系统概述 DICE-5210K是一款专为《MCS-51单片机原理与接口》、《C8051嵌入式单片机控制技术》、《自动化控制》、《CPLD/FPGA技术》等课程教学而设计的多功能单片机...

    Dice播放器 DicePlayer 2.0.54

    Dice播放器 DicePlayer 版本:2.0.54 大小:13 MB 适用固件:Android 2.2.X及以上 分享日期:2014-04-04 游戏题材:视频 开发商:INISOFT_DEV 内容介绍 DicePlayer是一款高性能播放器,基于硬件加速播放。HTC ...

    matlab开发-DiceGame

    【MATLAB开发-DiceGame】项目是一个基于MATLAB的趣味骰子游戏,旨在提供一个简单易学的游戏体验,无论玩家是独自一人还是与朋友或人工智能对战。MATLAB是一种强大的编程环境,通常用于科学计算、数据分析和算法开发...

    基于DICE—8086K的8255交通灯设计

    本文介绍了一项基于DICE—8086K实验箱的8255交通灯设计项目,该项目综合运用了微机原理与接口技术,以实现一个高效且功能丰富的交通灯管理系统。 ### 系统设计目标与要求 设计项目的初衷是为了让学生通过实践活动...

    图像分割评测指标,dice,voe,ASD,RVD等

    1. **Dice系数**(Dice Similarity Coefficient, DSC):也称为Sørensen-Dice系数,用于衡量两个集合的相似度。在图像分割中,它比较了预测分割区域与实际目标区域的重叠程度。DSC值范围在0到1之间,值越接近1表示...

    DICE-E213实验指导书20140814EP4CE6E22C8N核心卡.doc

    DICE-E213实验指导书20140814EP4CE6E22C8N核心卡说明文档。很全面很不错

    基于R语言的DICE模型实践技术应用

    专题一:DICE模型的原理与推导 1.经济学相关概念的回顾 2.气候变化问题 3.DICE模型的经济学部分 4.DICE模型的气候相关部分 5.DICE模型的目标函数与经济约束 6.DICE模型使用的地球物理方程 专题二:碳循环与...

    Dice-game-源码.rar

    "Dice-game-源码.rar"提供的就是一个关于骰子游戏的源代码,通过分析这个源码,我们可以深入理解游戏逻辑、随机数生成以及基本的用户交互等编程基础。 首先,我们需要知道的是,骰子游戏通常涉及到两个主要部分:...

Global site tag (gtag.js) - Google Analytics