题目传送门

题意:魔方最多旋转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. HDU 4915 Parenthese sequence

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4915 解题报告:从前往后遍历一次,每次判断')'的数目是不是满足 n < (i +1)/ 2,从 ...

  2. 如何在 Ubuntu Linux 16.04上安装开源的 Discourse 论坛

    导读 Discourse 是一个开源的论坛,它可以以邮件列表.聊天室或者论坛等多种形式工作.它是一个广受欢迎的现代的论坛工具.在服务端,它使用 Ruby on Rails 和 Postgres 搭建, ...

  3. Stanford机器学习---第二讲. 多变量线性回归 Linear Regression with multiple variable

    原文:http://blog.csdn.net/abcjennifer/article/details/7700772 本栏目(Machine learning)包括单参数的线性回归.多参数的线性回归 ...

  4. Kali Linux下破解WIFI密码挂载usb无线网卡的方法

    Kali Linux下破解WIFI密码挂载usb无线网卡的方法 时间:2014-10-12    来源:服务器之家    投稿:root 首先我要说的是,wifi密码的破解不是想象中的那么容易,目前还 ...

  5. Python: 什么是*args和**kwargs

    转自: http://blog.sina.com.cn/s/blog_65a8ab5d0101fglm.html http://blog.csdn.net/chenjinyu_tang/article ...

  6. 如何选择Html.RenderPartial和Html.RenderAction

    Html.RenderPartial与Html.RenderAction这两个方法都是用来在界面上嵌入用户控件的. Html.RenderPartial是直接将用户控件嵌入到界面上: <%Htm ...

  7. MVC ViewBag和ViewData的区别

    在MVC3开始,视图数据可以通过ViewBag属性访问,在MVC2中则是使用ViewData.MVC3中保留了ViewData的使用.ViewBag 是动态类型(dynamic),ViewData 是 ...

  8. spring事物传播属性

    PROPAGATION_REQUIRED Support a current transaction; create a new one if none exists.  支持一个当前事务;如果不存在 ...

  9. 《ASP.NET1200例》高亮显示ListView中的数据行并自动切换图片

    aspx <script type="text/javascript"> var oldColor; function SetNewColor(Source) { ol ...

  10. css定位左移动多少距离

    .main .logo { padding-left:82px; } 说明: .main .logo这个标签的路径离边框的距离是82Px