HDU 5012 Dice (bfs)

IDEA类和方法注释模板设置(非常详细) 阅读详情

Dice

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


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,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
 

Source
 

Recommend


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>

#define L(x) (x<<1)
#define R(x) (x<<1|1)
#define MID(x,y) ((x+y)>>1)
using namespace std;
#define N 700005

struct stud{
int a1,a2,a3,a4,a5,a0;
int time;
}s,e,t;

int ans;
int vis[N];

int fdd(struct stud x)
{
	int temp=0;
	temp+=x.a0*1;
	temp+=x.a1*7;
	temp+=x.a2*7*7;
	temp+=x.a3*7*7*7;
	temp+=x.a4*7*7*7*7;
	temp+=x.a5*7*7*7*7*7;

	return temp;
}

stud fddd(stud cur,int i)
{
	struct stud next;
	if(i==0)
	{
		next.a0=cur.a2;
		next.a1=cur.a3;
		next.a2=cur.a1;
		next.a3=cur.a0;
		next.a4=cur.a4;
		next.a5=cur.a5;
	}
	else
		if(i==1)
	{
		next.a0=cur.a3;
		next.a1=cur.a2;
		next.a2=cur.a0;
		next.a3=cur.a1;
		next.a4=cur.a4;
		next.a5=cur.a5;
	}
	else
		if(i==2)
	{
		next.a0=cur.a5;
		next.a1=cur.a4;
		next.a2=cur.a2;
		next.a3=cur.a3;
		next.a4=cur.a0;
		next.a5=cur.a1;
	}
	else
	{
		next.a0=cur.a4;
		next.a1=cur.a5;
		next.a2=cur.a2;
		next.a3=cur.a3;
		next.a4=cur.a1;
		next.a5=cur.a0;
	}
	return next;

}
int bfs()
{
	int temp,i;
	struct stud cur,next;

	memset(vis,0,sizeof(vis));

	temp=fdd(s);

    ans=fdd(e);

	vis[temp]=1;

	cur=s;

	cur.time=0;

	queue<stud>q;

	q.push(cur);

	while(!q.empty())
	{
		cur=q.front();
		q.pop();
		if(fdd(cur)==ans)
			return cur.time;

		for(i=0;i<4;i++) //旋转
		{
			stud t=fddd(cur,i);
			temp=fdd(t);
			if(!vis[temp])
			{
				t.time=cur.time+1;
				q.push(t);
				vis[temp]=1;
			}
		}
	}
	return -1;
}
int main()
{
	int i;
	while(~scanf("%d",&s.a0))
	{
		scanf("%d%d%d%d%d",&s.a1,&s.a2,&s.a3,&s.a4,&s.a5);

        scanf("%d%d%d%d%d%d",&e.a0,&e.a1,&e.a2,&e.a3,&e.a4,&e.a5);

	 printf("%d\n",bfs());
	}
}




计算机毕业设计springboot基于微信平台的二次元手办商场小程序【附源码】 选题背景: 随着二次元文化的兴起和普及,越来越多的人开始对二次元角色产生了浓厚的兴趣和喜爱。手办作为二次元文化的重要载体之一,成为了许多二次元爱好者收藏和展示的对象。然而,在传统的线下手办商场中,消费者往往面临着时间、空间和选择的限制。因此,基于微信平台的二次元手办商场小程序应运而生。 选题意义: 首先,基于微信平台的二次元手办商场小程序能够打破地域限制,使得用户可以随时随地通过手机进行购物。无论是在家中、上班途中还是旅行中,用户都能够方便地浏览和购买自己喜欢的手办,极大地提高了购物的便利性和灵活性。 阅读详情

相关推荐

在AVP28335(兼容德州仪器TMS320-28335) 上实现ModbusSlaveRTU-485源码及注释。

今天先把题目先给出来, 在近两天会把源码 (含详细注释 )及部署、测试结果给出来, 希望能给大家帮助。(全免费 我有点缺德,断了别人的一个财路)。

FOOLCODE的专栏 642

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

题干: 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,a6to be numbers written on top face, bottom face, left face, right ...

xuanweiace的博客 425

手把手教你用STM32实现SPWM逆变器控制(附完整代码)

本文提供了一份基于STM32实现SPWM逆变器控制的完整实战指南。文章从硬件选型(如STM32F103C8T6、IR2104驱动器)入手,详细解析了利用定时器TIM1生成SPWM波形的核心原理与代码实现,并涵盖了驱动电路、全桥功率电路及LC滤波器的设计要点与调试技巧,旨在帮助读者从零构建一个可靠的单相全桥逆变器系统。

weixin_29208327的博客 589

HDU5012 Dice(广搜BFS)

题目: Dice Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 1915    Accepted Submission(s): 952 Problem Description There are 2 s

riba2534的博客 538

axi ps读写pl_PL读写DDR:Datamover能干什么

最近发现工程项目中一直在用AXI-DMA。这玩意儿搬数据倒是没问题,就是用axi-lite配置起来非常反人类。。。简单的办法其实是用datamover ip核。这个ip核能干嘛呢。准备写个文章解析一下。由于好多feature没用过,所以仅仅看文档可能理解有误,欢迎指出错误。首先扫个盲:MM2S指的是Memory map to stream. 读DDR. S2MM指的是steam to memory...

weixin_35908791的博客 1597

Skiplist,B,B+tree,LSM tree

SkipList 理解(如何实现): 即使是有序的链表,查找的时间复杂度也是O(n),但链表不能随机访问所以不适用于二分查找,使得查找的时间复杂度为O(logn)。 于是将有序链表和二分查找结合得到了SkipList,类似于二叉搜索树,这是一种以空间换时间的算法,通过在每个节点中增加向前的指针,从而提升查找效率(如下图所示)。 一开始如a所示,是一个有序的链表,时间复杂度O(n)。随后建立了e所示的SkipList,从最顶层往下查找,可以跳过许多元素,减少查找次数。 ​

weixin_45875458的博客 947

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

大洋深处 1301

RK3588 hdmirx 调试(含v4l2工具,edid编辑)

RK3588 Buildroot系统中调试HDMI-RX的过程,包括抓图、修改EDID数据、编辑EDID等操作。首先,通过logcat和寄存器信息查询HDMI-RX的状态,使用v4l2-ctl工具进行测试和修改EDID。

501846585_QQAndroid_java 2684

hdu 5012(bfs)

题意:给你2个 骰子,让你通过翻转使第一个变成第二个,求最少翻转数 思路:bfs #include<cstdio> #include<iostream> #include<cstring> #include<cstdlib> #include<cmath> #include<algorithm&g...

diaocuiguo2493的博客 154

VS2022编译xlnt库

xlnt是一个用于读写Excel文件的C++库,本文介绍如何用源代码编译静态或动态xlnt库

QQVQQ的博客 7288

Android CCodec (十一) Codec2Buffer BufferPool分析

1、序言 2、C2BlockPool分析 3、SimpleC2Component关于BlockingBlockPool的实现 4、总结

给大佬递杯卡布奇诺的博客 4022

HDU - 5012 Dice

Dice Time Limit: 1000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u Submit Status Description There are 2 special dices on the table. On each face of the dic

luciozhang的博客 708

如何设置反馈点

前面的POWER DC仿真都是忽略反馈线进行的仿真,如果单板压降不过,电源会自动调整输出电压,来满足负载的得到额定的电压.可以看到因为设置了反馈点,源端电压就被抬高到满足压降的值了。仿真上也可以自己添加反馈点,以得到抬高后的电源输出电压值。同样以下图的CPU的Core电源为例。按照流程正常设置好参数。

weixin_54787054的博客 1146

HDU 5012 Dice (BFS)

其实是很水的一道bfs,用字符串表示每个状态,map判重就ok了。 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5012 #include #include #include #include #include #include #include #include #include #define N 7 using namespace std

ACM之路,在希望的田野上。 1292

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

HDU5012:Dice(bfs模板)

http://acm.hdu.edu.cn/showproblem.php?pid=5012Problem Description There are 2 special dices on the table. On each face of the dice, a distinct number was written...

weixin_31991991的博客 275

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

HDU - 5012 Dice BFS

题目大意:给出两个色子,只能进行四种操作,左转,右转,上转,下转,问能否经过旋转使两个色子的各面都相同 解题思路:直接暴力,用vis数组表示是否搜索过,这种解法接近1S,有点悬 #include #include #include #include #define maxn 700000 using namespace std; const int Z[4][6] = {{2,3,1,0,4,

静静地码 560

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

BFS + 剪枝 之 hdu 5012 Dice

/* BFS 遍历所有,当寻找到要转到的情况,输出BFS的层数,即答案,否则输出 -1; 注意: 剪枝: 当BFS到某一种状态时,若此状态已在前面所寻找的状态中出现过,则不用再继续从此状态BFS了,因为此状态所能寻找的状态已经处理过了。 */

JmingS 673

HDU - 5012 Dice(状压+BFS)

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,...

vocaloid01的博客 236

hdu 5012 Dice(bfs)

Dice Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 577Accepted Submission(s): 335 Problem Description There are ...

adr5970的博客 183

HDU-#5012 Dice(BFS)

题目大意:给定两个骰子,要按照只能左右前后的翻转方式,将两个骰子摆成状态一直的顺序,问最少需要多少步?      解题思路:不知道是喜还是忧,名次上升了,哈哈哈哈,真的只有一步之遥了!心情大好,接着发下昨天的题解吧!这个题是一个搜索题,很简单的,只需要将搜索的四个方向换成四种状态。就这一点的改变,其它就不赘述了,详见code。      题目来源:http://acm.hdu.edu.cn/s

VoidSun 453

HDU 5012 Dice bfs

Dice Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 701    Accepted Submission(s): 396 Problem Description There are 2 special dic

Clearlemon 599

HDU5012-Dice(BFS)

题目链接 题意:给你两个色子,如果可以通过旋转使两个色子的面一一对应相等(旋转规则题目给出),求最小步数,如果不行,输出-1。 思路:用BFS求最少步数。 代码: #include #include #include #include #include using namespace std; const int MAXN = 6; struct n

懒人一枚。 1453

Dice HDU - 5012(bfs)

Dice HDU - 5012 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...

codeswarrior的博客 284

hdu 5012 Dice(bfs)

DiceTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 2233    Accepted Submission(s): 1121Problem DescriptionThere are 2 special dices on the tabl...

Timeclimber 314

bfs-HDU 5012Dice

题意: 给出初状态,给出末状态,4个方向翻转最少几步。 思路: 一开始以为是个规律题。查了下是个搜索。知道是搜索就很好做了 #include #include #include using namespace std; struct node { int left,right,top,bottom,front,back,step; }; node save[10000]; i

GameRoad 398

hdu5012 Dice (bfs)

每次模拟  简单bfs,一直wa,只好找了北大的重写一遍 用vector记录节点信息,用map映射节点和步数

375
上一篇: HDU 4770 Lights Against Dudely
下一篇: HDU 5024 Wang Xifeng's Little Plot (bfs)
左眼皮跳跳~
博客等级 码龄13年 17粉丝 400原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值