模拟 ZOJ 3736 Pocket Cube

题目传送门

题意:魔方最多旋转n次,问最多能使多少面颜色相同

分析:6种状态(3种旋转方式*顺逆方向,其他对称的!),首先先打个表,然后很愉快的DFS。自己写的时候费劲脑汁,代码很长,还TLE了。。。。

/************************************************
* Author        :Running_Time
* Created Time  :2015/10/24 星期六 14:18:27
* File Name     :K.cpp
 ************************************************/

#include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std;

#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int N = 24;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const double EPS = 1e-8;
int ans;
int B[6][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}, //ok
               {20,1,22,3,10,4,0,7,8,9,11,5,2,13,14,15,6,17,12,19,16,21,18,23}, //ok
               {1,3,0,2,23,22,4,5,6,7,10,11,12,13,14,15,16,17,18,19,20,21,9,8}, //ok
               {2,0,3,1,6,7,8,9,23,22,10,11,12,13,14,15,16,17,18,19,20,21,5,4}, //ok
               {0,1,8,14,4,3,7,13,17,9,10,2,6,12,16,15,5,11,18,19,20,21,22,23}, //ok
               {0,1,11,5,4,16,12,6,2,9,10,17,13,7,3,15,14,8,18,19,20,21,22,23}  //ok
              };
int cal(int *a)   {
    int ret = 0;
    if (a[0] == a[1] && a[1] == a[2] && a[2] == a[3])   ret++;
    if (a[6] == a[7] && a[7] == a[12] && a[12] == a[13])    ret++;
    if (a[4] == a[5] && a[5] == a[10] && a[10] == a[11])    ret++;
    if (a[8] == a[9] && a[9] == a[14] && a[14] == a[15])    ret++;
    if (a[16] == a[17] && a[17] == a[18] && a[18] == a[19]) ret++;
    if (a[20] == a[21] && a[21] == a[22] && a[22] == a[23]) ret++;
    return ret;
}

void DFS(int tot, int *h)  {
    ans = max (ans, cal (h));
    if (!tot) {
        return ;
    }
    int p[24];
    for (int i=0; i<6; ++i) {
        for (int j=0; j<24; ++j)    p[j] = h[B[i][j]];
        DFS (tot - 1, p);
    }
    return ;
}

int main(void)    {
    int n;  int a[24];
    while (scanf ("%d", &n) == 1)   {
        for (int i=0; i<24; ++i)    scanf ("%d", &a[i]);
        ans = 0;
        DFS (n, a);
        printf ("%d\n", ans);
    }

    return 0;
}

  

时间: 2025-01-05 05:52:29

模拟 ZOJ 3736 Pocket Cube的相关文章

[dfs] zoj 3736 Pocket Cube

题目链接: 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

HDU 4801 Pocket Cube(模拟题——转魔方)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4801 题面: Pocket Cube Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 882    Accepted Submission(s): 271 Problem Description Pocket Cube is a 3-D

HDU 5983 Pocket Cube

Pocket Cube Problem Description The Pocket Cube, also known as the Mini Cube or the Ice Cube, is the 2 × 2 × 2 equivalence of a Rubik's Cube.The cube consists of 8 pieces, all corners.Each piece is labeled by a three dimensional coordinate (h, k, l)

2013区域赛长沙赛区现场赛 K - Pocket Cube

K - Pocket Cube Time Limit:10000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 4801 Description Pocket Cube is a 3-D combination puzzle. It is a 2 × 2 × 2 cube, which means it is constructed by 8 mini-cubes.

ZOJ 2477 Magic&#160;Cube(魔方)

ZOJ 2477 Magic Cube(魔方) Time Limit: 2 Seconds      Memory Limit: 65536 KB This is a very popular game for children. In this game, there's a cube, which consists of 3 * 3 * 3 small cubes. We can unwrap the cube, it will become like this: 这是个有名的儿童游戏.游戏

HDU 4801 Pocket Cube BFS

链接:http://vjudge.net/contest/view.action?cid=51289#problem/K 题意:给一个小魔方(每面只有四个小块),每个小块有自己的颜色(一共六种颜色,每种颜色四块),问经过最多N次操作(N<=7),每次操作是将魔方某一面转动90度,最多能使多少个面的四个小块颜色都相同. 思路:每次操作产生6种状态,(向前,向后,向左,向右,向上,向下,左半魔方向前和右半魔方向后的操作产生的状态本质是一样的)直接BFS搜索,可能产生的状态一共有6^7种,中间比较麻烦

2016ACM/ICPC亚洲区青岛站 B Hdu-5983 Pocket Cube 模拟

题面 题意:给你一个2*2的魔方,给你每个面每个小块的颜色,一共24个,然后问你能否在一步之内还原. 题解:手动在纸上画,推出每种变化对应的置换,显然,一共有6种,而且可以当成3种,(具体哪3种,就是绕x,y,z轴转一次的),另外一个方向,就是转三次就行了 而且你也不需要考虑什么上面转了下面转,相对关系是一样的 写的时候犯了个错,手写的u,v,r分不清楚了..... 转一次会有12个小面发生变化,写的时候可以只写8个面,因为有一个面的位置变了, 但是我们只问一步之内能不能还原,那一面的都没有到其

BFS+模拟 ZOJ 3865 Superbot

题目传送门 1 /* 2 BFS+模拟:dp[i][j][p] 表示走到i,j,方向为p的步数为多少: 3 BFS分4种情况入队,最后在终点4个方向寻找最小值:) 4 */ 5 #include <cstdio> 6 #include <iostream> 7 #include <algorithm> 8 #include <cstring> 9 #include <string> 10 #include <queue> 11 usi

模拟 ZOJ 3878 Convert QWERTY to Dvorak

题目传送门 1 /* 2 模拟:手敲map一一映射,累! 3 除了忘记读入字符串不能用gets用getline外还是很顺利的AC了:) 4 */ 5 #include <cstdio> 6 #include <iostream> 7 #include <algorithm> 8 #include <cmath> 9 #include <cstring> 10 #include <string> 11 #include <map&