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. 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 separated by a single 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

转魔方,bfs,一直找不到wa在哪里。这题思考魔方的旋转有点烦。

有6种旋转方式,而不是12种。。

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<vector>
 5 #include<queue>
 6 #include<algorithm>
 7 #include<map>
 8 #define INF 0x3f3f3f3f
 9 #define M(a,b) memset(a,b,sizeof(a))
10
11 using namespace std;
12
13 int state[24];
14 int change[6][24]={
15     {6,1,12,3,5,11,16,7,8,9,4,10,18,13,14,15,20,17,22,19,0,21,2,23},
16     {20,1,22,3,10,4,0,7,8,9,11,5,2,13,14,15,6,17,12,19,16,21,18,23},
17     {1,3,0,2,23,22,4,5,6,7,10,11,12,13,14,15,16,17,18,19,20,21,9,8},
18     {2,0,3,1,6,7,8,9,23,22,10,11,12,13,14,15,16,17,18,19,20,21,5,4},
19     {0,1,11,5,4,16,12,6,2,9,10,17,13,7,3,15,14,8,18,19,20,21,22,23},
20     {0,1,8,14,4,3,7,13,17,9,10,2,6,12,16,15,5,11,18,19,20,21,22,23},
21 };
22
23 int N;
24 int ans;
25
26 struct tube
27 {
28     int d[24];
29     int cnt;
30     tube(){}
31 };
32 tube st;
33 tube trans(tube tmp,int k)
34 {
35     tube res;
36
37     for (int i=0; i<24; i++)
38     res.d[i]=tmp.d[change[k][i]];
39
40     return res;
41 }
42 int count(tube tmp)
43 {
44     int res=0;
45     if (tmp.d[0]==tmp.d[1] && tmp.d[1]==tmp.d[2] && tmp.d[2]==tmp.d[3]) res++;
46     if (tmp.d[8]==tmp.d[9] && tmp.d[14]==tmp.d[15] && tmp.d[8]==tmp.d[14]) res++;
47     if (tmp.d[6]==tmp.d[7] && tmp.d[7]==tmp.d[12] && tmp.d[12]==tmp.d[13]) res++;
48     if (tmp.d[4]==tmp.d[5] && tmp.d[5]==tmp.d[11] && tmp.d[11]==tmp.d[10]) res++;
49     if (tmp.d[16]==tmp.d[17] && tmp.d[17]==tmp.d[19] && tmp.d[19]==tmp.d[18]) res++;
50     if (tmp.d[20]==tmp.d[21] && tmp.d[21]==tmp.d[22] && tmp.d[22]==tmp.d[23]) res++;
51     return res;
52 }
53
54 void bfs()
55 {
56     queue<tube> q;
57     q.push(st);
58 //    map<tube,int> mp;
59 //    mp[st]=1;
60     ans=count(st);
61     while(!q.empty())
62     {
63         tube now=q.front();
64         q.pop();
65         tube tmp;
66         for (int i=0; i<6; i++)
67         {
68             tmp=trans(now,i);
69             tmp.cnt=now.cnt+1;
70 //            if (mp.find(tmp)!=mp.end())
71 //            {
72 //                mp[tmp]=1;
73 //                ans=max(ans,count(tmp));
74 //                if (tmp.cnt<num) q.push(tmp);
75 //            }
76             ans=max(ans,count(tmp));
77             if (tmp.cnt<N) q.push(tmp);
78         }
79     }
80 }
81
82 int main()
83 {
84    //init();
85    while(scanf("%d",&N)==1)
86    {
87        for(int i = 0;i<24;i++)
88        {
89             scanf("%d",&st.d[i]);
90         }
91         st.cnt=0;
92         bfs();
93        printf("%d\n",ans);
94    }
95    return 0;
96 }
时间: 2024-08-24 22:48:23

2013区域赛长沙赛区现场赛 K - Pocket Cube的相关文章

2013长沙赛区现场赛 J - Josephina and RPG

J - Josephina and RPG Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 4800 Description A role-playing game (RPG and sometimes roleplaying game) is a game in which players assume the roles of cha

ZOJ3822 ACM-ICPC 2014 亚洲区域赛牡丹江赛区现场赛D题Domination 概率DP(两种解法)

题目地址:点击打开链接 这道题有两种做法,第一种是直接求期望,类似于poj 2096 区别在于这个步数有限.所以要迭代步数. #include <cstdio> #include <cstring> #include <iostream> #define maxn 55//这里刚开始写成了50+10 那么maxn*maxn就会小很多wa了一次 using namespace std; double dp[maxn][maxn][maxn*maxn]; int N,M,T

2014ACM/ICPC亚洲区鞍山赛区现场赛——题目重现

2014ACM/ICPC亚洲区鞍山赛区现场赛--题目重现 题目链接 5小时内就搞了5题B.C.D.E,I. H题想到要打表搞了,可惜时间不够,后面打出表试了几下过了- - K题过的人也比较多,感觉是个几何旋转+ploya,但是几何实在不行没什么想法 B:这题就是一个大模拟,直接数组去模拟即可,注意细节就能过 C:类似大白上一题红蓝三角形的, 每个数字找一个互质和一个不互质个数,除掉重复就直接除2,然后总的C(n, 3)减去即可,问题在怎么处理一个数字互质和不互质的,其实只要处理出不互质的即可,这

HDU 4119 Isabella&#39;s Message (2011年成都赛区现场赛I题)

1.题目描述:点击打开链接 2.解题思路:本题是一道模拟题,要求模拟一个解密的过程,练习这么久第一次做模拟题1Y了,内心还是很激动的~.只需要根据题意,记录* 所在的位置即可,然后每次都是先解密,后顺时针旋转90度.把每次解密的信息放到一个vector里,接下来就是连接它们,得到解密后的字符串,在map中查找这些单词是否存在即可.如果都存在,就把这条解密信息放到ans中,最后对ans排序,输出ans[0]就是答案. 3.代码: //#pragma comment(linker, "/STACK:

擦肩而过的那块牌--记ACM_ICPC西安赛区现场赛

说了那么多次orz,这次是真的orz了,去了西安打区域赛,也想过会打铁,但当最终那一刻确定打铁了之后,心里还是很不开心的,颁奖的时候思考熊那家伙嚣张的举起来手中那个金杯,说实话闪到我眼了(太亮了QAQ),打铁怨谁,这不好说,很多因素,别人别的我就不说了,但不能读英语实在让我不能忍,都说读不懂,带的那本字典几乎都没翻我会乱说?比完赛怨不该开f题,但当时3个半小时没人看i题,也怨我,一看到min就怯了,后来揭榜看到离铜牌区差8名,差12分钟..我呵呵了,第二题re一次罚时20分钟,可以说那次罚时也是

2013 长沙现场赛 K (Pocket Cube)

题意: 给出一个2X2X2的魔方,再给一个限定的步骤长度,不超过该长度最多能能使几个面拼成功. 纯粹模拟题,搞清楚几个面的变换关系,并化简步骤,三种旋转方式,两种旋转方向.bfs,dfs都可以. #include <stdio.h> #include <string.h> #define maxn 300000 int twist[3][3][4]= { {{1,7,17,21}, {3,13,19,23}, {9,8,14,15}}, {{2,11,17,8}, {3,5,16,

ACM-ICPC 2018 青岛赛区现场赛 K. Airdrop &amp;&amp; ZOJ 4068 (暴力)

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4068 题意:吃鸡游戏简化为二维平面上有 n 个人 (xi,yi),空投的位置在 (x0,y0),每一秒所有人向靠近空投的位置走一步,四个方向有优先级先后(优先纵坐标),若已经在空投的位置则不变.往空投位置移动过程中,若两个或者更多人在同一点相遇(在空投相遇不算),则他们都死亡.给出空投的纵坐标,询问空投在所有横坐标中最少和最多存活的人数是多少. 题解:在最优情况

2014ACM/ICPC亚洲区域赛牡丹江站现场赛-K ( ZOJ 3829 ) Known Notation

Known Notation Time Limit: 2 Seconds      Memory Limit: 65536 KB Do you know reverse Polish notation (RPN)? It is a known notation in the area of mathematics and computer science. It is also known as postfix notation since every operator in an expres

2014年ACM牡丹江赛区现场赛K题(ZOJ 3829)

Known Notation Time Limit: 2 Seconds      Memory Limit: 65536 KB Do you know reverse Polish notation (RPN)? It is a known notation in the area of mathematics and computer science. It is also known as postfix notation since every operator in an expres