[dfs] zoj 3736 Pocket Cube

从零到一:RT-Thread与W5500的硬件抽象层设计哲学与实践启示 本文深入探讨了RT-Thread操作系统下W5500以太网模块的硬件抽象层(HAL)设计哲学与实践。通过GD32F103和STM32F103平台的适配案例,详细阐述了如何利用RT-Thread的驱动框架实现跨平台硬件无关性、模块化设计及配置定制,为嵌入式开发者提供了可复用的HAL设计方法论和实战经验。 阅读详情

题目链接:

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3736

Pocket Cube

Time Limit: 2 Seconds       Memory Limit: 65536 KB

Pocket Cube is a 3-D combination puzzle. It is a 2 × 2 × 2 cube, which means it is constructed by 8 mini-cubes. For a combination of 2 × 2 mini-cubes which sharing a whole cube face, you can twist it 90 degrees in clockwise or counterclockwise direction, this twist operation is called one twist step.

Considering all faces of mini-cubes, there will be totally 24 faces painted in 6 different colors (Indexed from 0), and there will be exactly 4 faces painted in each kind of color. If 4 mini-cubes' faces of same color rely on same large cube face, we can call the large cube face as a completed face.

   

Now giving you an color arrangement of all 24 faces from a scrambled Pocket Cube, please tell us the maximum possible number of completed faces in no more than N twist steps.

Index of each face is shown as below:

Input

There will be several test cases. In each test case, there will be 2 lines. One integer N (1 ≤ N ≤ 7) in the first line, then 24 integers Ci seperated by a sinle space in the second line. For index 0 ≤ i < 24, Ci is color of the corresponding face. We guarantee that the color arrangement is a valid state which can be achieved by doing a finite number of twist steps from an initial cube whose all 6 large cube faces are completed faces.

Output

For each test case, please output the maximum number of completed faces during no more than N twist step(s).

Sample Input
1
0 0 0 0 1 1 2 2 3 3 1 1 2 2 3 3 4 4 4 4 5 5 5 5
1
0 4 0 4 1 1 2 5 3 3 1 1 2 5 3 3 4 0 4 0 5 2 5 2
Sample Output
6
2

Author:  FAN, Yuzhe;CHEN, Cong;GUAN, Yao
Contest:  The 2013 ACM-ICPC Asia Changsha Regional Contest
Submit     Status

题目意思:

给2*2*2的魔方,求在给定的n步内最多可以凑成多少完整的面。

解题思路:

由于n<=7,所以暴搜即可。

每种状态下有6种选择,(不是12种,因为转动右边可以转化为转动左边,转动下面可以转化为转动上面,转动后面可以转化为转动前面)

所以只用考虑左边、下面、后面的各两种情况。

找出各位置新的状态下在原来的位置标号。

Tips: 当数组指针作为参数传给函数时,不能在里面用memcpy,因为此时并不知道该数组的大小

当全局数组指针作为参数传给函数时,每个递归函数里面对指针所指内容所做的修改,都会生效,并且有可能访问的都是同一个内存区域。

当传数组指针时,最好使用局部数组这样才不会有问题。

代码:

//#include<CSpreadSheet.h>

#include<iostream>
#include<cmath>
#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<string>
#include<string.h>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<ctime>
#include<bitset>
#include<cmath>
#define eps 1e-6
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
#define ll __int64
#define LL long long
#define lson l,m,(rt<<1)
#define rson m+1,r,(rt<<1)|1
#define M 1000000007
//#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;

#define Maxn 30

int cur[Maxn],vv[Maxn],n,ans;

int next[][24]=
{
    {6,1,12,3,5,11,16,7,8,9,4,10,18,13,14,15,20,17,22,19,0,21,2,23},//左边往内
    {20,1,22,3,10,4,0,7,8,9,11,5,2,13,14,15,6,17,12,19,16,21,18,23},//左边往外
    {0,1,11,5,4,16,12,6,2,9,10,17,13,7,3,15,14,8,18,19,20,21,22,23},//下面往内
    {0,1,8,14,4,3,7,13,17,9,10,2,6,12,16,15,5,11,18,19,20,21,22,23},//下面往外
    {2,0,3,1,6,7,8,9,23,22,10,11,12,13,14,15,16,17,18,19,20,21,5,4},//后面往下
    {1,3,0,2,23,22,4,5,6,7,10,11,12,13,14,15,16,17,18,19,20,21,9,8} //后面忘上
};
int cal(int * cur) //统计完整面的个数
{
    int res=0;

    if(cur[0]==cur[1]&&cur[0]==cur[2]&&cur[0]==cur[3])
        res++;
    if(cur[4]==cur[5]&&cur[4]==cur[10]&&cur[4]==cur[11])
        res++;
    if(cur[6]==cur[7]&&cur[6]==cur[12]&&cur[6]==cur[13])
        res++;
    if(cur[8]==cur[9]&&cur[8]==cur[14]&&cur[8]==cur[15])
        res++;
    if(cur[16]==cur[17]&&cur[16]==cur[18]&&cur[16]==cur[19])
        res++;
    if(cur[20]==cur[21]&&cur[20]==cur[22]&&cur[20]==cur[23])
        res++;
    return res;
}
void dfs(int num,int * cur)
{
    ans=max(ans,cal(cur));
    if(num>n)
        return ;
    int vv[Maxn]; //该数组定义成全局变量会有问题
    for(int i=0;i<6;i++)
    {
        for(int j=0;j<24;j++)
            vv[j]=cur[next[i][j]]; //如果vv是全局的,vv和cur会指向同一块内存,访问会出现混乱
        dfs(num+1,vv);
    }
}

int main()
{
   //freopen("in.txt","r",stdin);
   //freopen("out.txt","w",stdout);
   while(~scanf("%d",&n))
   {
       for(int i=0;i<24;i++)
            scanf("%d",&cur[i]);
       ans=0;
       dfs(1,cur);
       printf("%d\n",ans);
   }

   return 0;
}


R语言中的Gamma分布函数 在R语言中,我们可以使用最大似然估计(Maximum Likelihood Estimation,MLE)或最小二乘估计(Least Squares Estimation,LSE)等方法来估计Gamma分布的参数。本文介绍了在R语言中使用Gamma分布函数的基本操作,包括生成随机变量、计算概率密度函数和累积分布函数,以及参数估计和拟合。函数来生成Gamma分布的随机变量,计算概率密度函数(PDF)和累积分布函数(CDF),以及进行参数估计和拟合。要计算Gamma分布的累积分布函数(CDF),我们可以使用。 阅读详情

相关推荐

思维链:让AI更接近人类思维的技术

本文将探讨一种名为“思维链”的技术,它旨在让AI更接近人类思维。文章首先介绍了问题背景与核心概念,接着讲解了算法原理和数学模型,随后阐述了系统分析与架构设计,最后通过项目实战展示了思维链的实际应用,并提供了最佳实践和小结。思维链是一种旨在模拟人类思维过程的技术,它通过构建一系列相互关联的思维方式,实现对复杂问题的分析和解决。思维链算法是一种基于人类思维过程的人工智能算法,它通过构建一系列思维链,实现对问题的分析和解决。智能问答系统是一种常见的人工智能应用,它能够回答用户提出的各种问题。

AI天才研究院 896

ZOJ - 3736 Pocket Cube (模拟暴搜)

Pocket Cube Pocket Cube is a 3-D combination puzzle. It is a 2 × 2 × 2 cube, which means it is constructed by 8 mini-cubes. For a combination of 2 × 2 mini-cubes which sharing a whole cube face, y...

YOONGI 258

ADC的dma法_STM32F103_stm32f103调试adc_DMA如何调试_

STM32F103的ADC功能调试(需要串口),编程软件是Keil uVision5

ZOJ 3736 Pocket Cube

唯一思考点:左侧顺时针转等价于右侧逆时针转,12种转法变6种 类型:水题 总结:我很蠢 #include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #define INF 0x7f7f7f7f using namespace std; ...

weixin_30955341的博客 80

Pocket CubeZOJ - 3736】【爆搜模拟】

题目链接 题目大意 给你一个二阶魔方,问你转n次最多转出多少个面。 解题思路 啥都不说了… … …搜就完了… … … 这代码打的我有点上头 #include<stdio.h> #include<string.h> #include<algorithm> using namespace std; int a[40],ans,n; int F() { int...

qq_41925919的博客 186

zoj 3736 Pocket Cube(2013亚洲区域赛 长沙站 K)

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3736     Pocket Cube is a 3-D combination puzzle. It is a 2 × 2 × 2 cube, which means it is constructed by 8 mini-cubes. For a combi

ddyyxx的程序员之路 2529

LA 6621 /ZOJ 3736 Pocket Cube 打表+暴力

这道题是长沙区域赛的一道简单题,当时题目在ZOJ重现的时候就做了一次,但是做的好复杂,用的BFS暴力,而且还没打表,最后还是莫名其妙的爆栈错误,所以就一直没弄出来,昨天做到大白书上例题05年东京区域赛的一道类似题 Colored Cubes,这类题都需要脑补一下立方体的旋转总共有几种状态,然后用函数或者手工打表来记叙每一次变化之后的立方体变化 这道题从编号开始就给了我们很大便利,从0-...

weixin_30826095的博客 148

模拟 ZOJ 3736 Pocket Cube

题目传送门 题意:魔方最多旋转n次,问最多能使多少面颜色相同 分析:6种状态(3种旋转方式*顺逆方向,其他对称的!),首先先打个表,然后很愉快的DFS。自己写的时候费劲脑汁,代码很长,还TLE了。。。。 /************************************************ * Author :Running_Time * Cre...

weixin_34199405的博客 60

ZOJ 3736 & HDU 4801 - Pocket Cube 打表搜索

题意:                         给了一个2*2的魔方..每步操作可以将任意一面翻转90度..现在问在N(                题解:                         开始自己打了个10行表..好难找错..然后发现..其实只要六个就行了..因为左侧正90转和右侧负90转时一样的..                         论科学打表.

zzyzzy12 1773

poj 1768 Hang or not to hang 离散化+搜索+状态压缩

题目链接: http://poj.org/problem?id=1768 题目意思: 给你n种命令,最多32个寄存器,问可能的最少的执行命令次数,使程序终止。 解题思路: 对于不能直接和间接影响JZ中的寄存器的寄存器的状态可以是任意,因为他们每一步都是确定的,最终命令执行的次数与初始状态无关。 所以先找出直接和间接影响JZ中的寄存器的寄存器,由于命令最多只有16个,所以除去STOP

cc_again的专栏 1781

[dfs] UVALive 3667 Ruler

题目链接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1668 Root    Regionals 2006 >> Asia - Beijing 3667 - Ruler Ti

cc_again的专栏 1653

简单搜索(数独)poj 2676 Sudoku

题目链接: http://poj.org/problem?id=2676 题目意思: 数独填数。 解题思路: 可以o(1)检查是否可能。 row[i][j]表示第i行的数j是否已填。(false表示未填,true表示已填) col[i][j]表示第i列的数j是否已填。(false表示未填,true表示已填) bl[i][j]表示第i块的数j是否已填。(false表示未填,tru

cc_again的专栏 1519

BFS+思维-poj-3182-The Grove

题目链接: http://poj.org/problem?id=3182 题目大意: 有一片紧凑的森林不能访问,给一个起点,问从起点出发,可以上下左右斜对角8个方向走,求最小的步数能够围住森林并且回到起点。 解题思路: 思维+BFS. 先找到森林到右边界的一条线段。显然,要求的路径肯定要穿过这条线段。所以从这条线段中的每个点两遍BFS,一遍控制开始的方向非下,另一遍控制开始的方向非

cc_again的专栏 1482

BFS-hdu-4101-Ali and Baba

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4101 题目大意: 给一个矩阵,0表示空的可走,-1宝藏的位置(只有一个),其余的正整数表示该位置石头数。甲乙两个人,轮流玩游戏。甲先玩,谁先从外面通过空路径到达了宝藏的位置(不能经过石头),谁就获胜。如果不能直接到达宝藏位置,可以从外面通过空到某个位置,拿走该位置上的一个石头,如果该位置没

cc_again的专栏 1453

ID(dfs+bfs)-hdu-4127-Flood-it!

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4127 题目意思: 给n*n的方格,每个格子有一种颜色(0~5),每次可以选择一种颜色,使得和左上角相连(颜色相同以及相邻,间接也行)的所有的格子都为该颜色。求最少的步数,使得所有的方格颜色都相同。 解题思路: bfs+bfs死活不给过。 正确解法应该是IDA(dfs+bfs).因为总

cc_again的专栏 1345

BFS+余数判重+数论 hdu-1664-Different Digits

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1664 题目意思: 给一个n,让你找出含不同数字最少的n的倍数,如果含不同数字相同,则输出最小的。 解题思路: 根据数论里面的知识点: 对于任意的整数n,必然存在一个由不多于两个的数来组成的一个倍数。因为a,aa,aaa……取n+1个,则由鸽笼原理,必有两个模n余数相同,相减即得n

cc_again的专栏 1335

[迭代加深dfs] zoj 3768 Continuous Login

题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3768 Continuous Login Time Limit: 2 Seconds      Memory Limit: 131072 KB      Special Judge Pierre is recently obsessed

cc_again的专栏 1327

BFS hdu-4528 小明系列故事——捉迷藏

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4528 题目意思: 给你一个矩阵,'.‘ 表示能通过,’X' 表示不能通过,告诉你S、D、E 的位置。 问你从S出发在规定的时间内,能否同时找到D和E。只要两个人之间没有障碍,就能找到。 解题思路: BFS,注意记录访问过的节点的时候,要注意状态的确定。 vis[x][y][i][j

cc_again的专栏 1258

dfs) hdu 4394 Digital Square

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4394 题目意思: 给定一个N(0 解题思路: 搜索。 从低位往高位依次处理。    abcde * abcde ------------ N(...n3n2n1) 显然可以根据N的个位确定e的可能的情况,把e确定后,再根据2*d*e=n2,得出d的可能情况,再根据2*c*e

cc_again的专栏 1234

基于SSM的社区物业管理系统设计.zip

基于SSM的社区物业管理系统设计.zip

上一篇: [二分+容斥原理] poj 2773 Happy 2006
下一篇: [计算几何] zoj 3728 Collision
Accagain
博客等级 码龄14年 376粉丝 316原创
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值