题目传送门

题意:魔方最多旋转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;
}

  

模拟 ZOJ 3736 Pocket Cube的更多相关文章

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

    这道题是长沙区域赛的一道简单题,当时题目在ZOJ重现的时候就做了一次,但是做的好复杂,用的BFS暴力,而且还没打表,最后还是莫名其妙的爆栈错误,所以就一直没弄出来,昨天做到大白书上例题05年东京区域赛 ...

  2. Pocket Cube

    Pocket Cube http://acm.hdu.edu.cn/showproblem.php?pid=5983 Time Limit: 2000/1000 MS (Java/Others)    ...

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

    K - Pocket Cube Time Limit:10000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Su ...

  4. ZOJ 2477 Magic Cube(魔方)

    ZOJ 2477 Magic Cube(魔方) Time Limit: 2 Seconds      Memory Limit: 65536 KB This is a very popular gam ...

  5. HDU 5292 Pocket Cube 结论题

    Pocket Cube 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5292 Description Pocket Cube is the 2×2× ...

  6. 【】【】Pocket Cube

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

  7. ZOJ 3736 模拟魔方

    题意:       2*2*2的魔方,给你一个初始状态,和一个限定步数,问你在这么多步数条件下最多能有多少面拼好,(不是累加关系,是某一个状态的最多,最多是6); 思路:      最多是7步,所以直 ...

  8. ZOJ 2477 Magic Cube 暴力,模拟 难度:0

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1477 用IDA*可能更好,但是既然时间宽裕数据简单,而且记录状态很麻烦,就直接 ...

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

    题面 题意:给你一个2*2的魔方,给你每个面每个小块的颜色,一共24个,然后问你能否在一步之内还原. 题解:手动在纸上画,推出每种变化对应的置换,显然,一共有6种,而且可以当成3种,(具体哪3种,就是 ...

随机推荐

  1. Python os.system 和 os.popen的区别

    (1) os.system # 仅仅在一个子终端运行系统命令,而不能获取命令执行后的返回信息 system(command) -> exit_statusExecute the command ...

  2. c++11 gcc4.8.x安装

    c++11 gcc4.8.x安装 2014年12月11日默北   要安装PHP-CPP,需要c++11,否则就会报错,错误信息如下所示: g++ -Wall -c -g -std=c++11 -fpi ...

  3. CSS3弹性盒模型flexbox完整版教程

    http://caibaojian.com/flexbox-guide.html 来自CSS Tricks上的一个教程,原文为:A Complete Guide to Flexbox.文中详细的介绍了 ...

  4. shell笔记-local、export用法 、declare、set

    local一般用于局部变量声明,多在在函数内部使用.     1.    Shell脚本中定义的变量是global的,其作用域从被定义的地方开始,到shell结束或被显示删除的地方为止.     2. ...

  5. 【云计算】实战-五个Docker监控工具的对比

    [实战]五个Docker监控工具的对比 阅读目录 Docker Stats命令 CAdvisor Scout Data Dog Sensu Monitoring Framework 总结 这篇文章作者 ...

  6. 【leetcode】Excel Sheet Column Number

    Excel Sheet Column Number Related to question Excel Sheet Column Title Given a column title as appea ...

  7. (转)maven eclipse debug

    准备工作: a. 在pom.xml中配置jetty插件: <plugins> <plugin> <groupId>org.mortbay.jetty</gro ...

  8. centos 编译安装Apache 2.4

    2013年12月29日 16:40:20 ./configure --prefix=/usr/local/web/apache --enable-so --enable-rewrite --enabl ...

  9. 4.django笔记之admin

    作者:刘耀 QQ:22102107 django-Admin django amdin是django提供的一个后台管理页面,改管理页面提供完善的html和css,使得你在通过Model创建完数据库表之 ...

  10. js监听密码输入框type

    1.密码输入框 <input class="oaInput oaText" type="text" placeholder="请输入用户名&qu ...