• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
HaibaraAi
博客园    首页    新随笔    联系   管理    订阅  订阅

2012 Asia Changsha Regional Contest Problem K

Pocket Cube

Time Limit: 2 Seconds      Memory Limit: 65536 KB

这题写的真的*痛- -#,全局数组变了全局传过去的tmp数组也变了不知道,见识太少- -#~

因为2阶魔方本来有12中转每个面有2中方向,但是右边顺时针和左边逆时针是相同的所以其实只有6种转法!

预处理下转动后的情况就行了!

如果考虑翻转的话可以只有4种,但是不好判重,翻转又不算次数,所以还是直接6种爆搜好,标记啊,判重啊什么的,一个是为了减少次数,另一方面可以避免死循环(-。-;)!

不过这题直接爆就行了!

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

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 using namespace std;
 5 #define maxn 100010
 6 int n, m, s, x, d, ans;
 7 int a[31];
 8 int p[6][24] = {
 9     {6,1,12,3,5,11,16,7,8,9,4,10,18,13,14,15,20,17,22,19,0,21,2,23},
10     {20,1,22,3,10,4,0,7,8,9,11,5,2,13,14,15,6,17,12,19,16,21,18,23},
11     {1,3,0,2,23,22,4,5,6,7,10,11,12,13,14,15,16,17,18,19,20,21,9,8},
12     {2,0,3,1,6,7,8,9,23,22,10,11,12,13,14,15,16,17,18,19,20,21,5,4},
13     {0,1,11,5,4,16,12,6,2,9,10,17,13,7,3,15,14,8,18,19,20,21,22,23},
14     {0,1,8,14,4,3,7,13,17,9,10,2,6,12,16,15,5,11,18,19,20,21,22,23},
15 };
16 int judge(int *tmp){
17     int t = 0;
18     if (tmp[0] == tmp[1] && tmp[1] == tmp[2] && tmp[2] == tmp[3])t++;
19     if (tmp[4] == tmp[5] && tmp[5] == tmp[10] && tmp[10] == tmp[11])t++;
20     if (tmp[6] == tmp[7] && tmp[7] == tmp[12] && tmp[12] == tmp[13])t++;
21     if (tmp[8] == tmp[9] && tmp[9] == tmp[14] && tmp[14] == tmp[15])t++;
22     if (tmp[16] == tmp[17] && tmp[17] == tmp[18] && tmp[18] == tmp[19])t++;
23     if (tmp[20] == tmp[21] && tmp[21] == tmp[22] && tmp[22] == tmp[23])t++;
24     return t;
25 }
26 void dfs(int *tmp,int k){
27     int f[41];
28     ans = max(ans, judge(tmp));
29     if (k==n)return;
30     for (int i = 0; i < 6; i++){
31         for (int j = 0; j < 24; j++)f[j] = tmp[p[i][j]]; 
32         dfs(f,k + 1);
33     }
34 }
35 int main(){
36     while (~scanf("%d", &n)){
37         ans = 0;
38         for (int i=0;i<24;i++)scanf("%d", &a[i]);
39         dfs(a,0);
40         printf("%d\n", ans);
41     }
42     return 0;
43 }
View Code
posted @ 2013-12-07 01:04  HaibaraAi  阅读(87)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3