The 2013 ACM-ICPC Asia Changsha Regional Contest - K
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 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
一共是12种变化,但是有等价的,最后每一纬是2种变换,一共是6种变换。
#include <iostream>
#include <string>
#include <string.h>
#include <map>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <vector>
#include <math.h>
#include <set>
#define Max(a,b) ((a)>(b)?(a):(b))
#pragma comment(linker, "/STACK:16777216")
using namespace std ;
typedef long long LL ;
struct Cube{
int a[] ; void out(){
printf(" %d%d \n",a[],a[]) ;
printf(" %d%d \n",a[],a[]) ;
printf("%d%d%d%d%d%d\n",a[],a[],a[],a[],a[],a[]) ;
printf("%d%d%d%d%d%d\n",a[],a[],a[],a[],a[],a[]) ;
printf(" %d%d \n",a[],a[]) ;
printf(" %d%d \n",a[],a[]) ;
printf(" %d%d \n",a[],a[]) ;
printf(" %d%d \n",a[],a[]) ;
puts("") ;
} int complete_face(){
int sum = ;
if(a[]==a[]&&a[]==a[]&&a[]==a[])
sum++ ;
if(a[]==a[]&&a[]==a[]&&a[]==a[])
sum++ ;
if(a[]==a[]&&a[]==a[]&&a[]==a[])
sum++ ;
if(a[]==a[]&&a[]==a[]&&a[]==a[])
sum++ ;
if(a[]==a[]&&a[]==a[]&&a[]==a[])
sum++ ;
if(a[]==a[]&&a[]==a[]&&a[]==a[])
sum++ ;
return sum ;
} Cube R_colock(){
Cube o ;
for(int i = ;i < ;i++)
o.a[i] = a[i] ;
o.a[] = a[] ;
o.a[] = a[] ;
o.a[] = a[] ;
o.a[] = a[] ;
o.a[] = a[] ;
o.a[] = a[] ;
o.a[] = a[] ;
o.a[] = a[] ;
o.a[] = a[] ;
o.a[] = a[] ;
o.a[] = a[] ;
o.a[] = a[] ;
return o ;
} Cube R_count_colock(){
Cube o ;
for(int i = ;i < ;i++)
o.a[i] = a[i] ;
o.a[]= a[];
o.a[]= a[];
o.a[]= a[];
o.a[]= a[] ;
o.a[]= a[] ;
o.a[] =a[];
o.a[] =a[];
o.a[] =a[];
o.a[] =a[];
o.a[] =a[];
o.a[] =a[];
o.a[] =a[];
return o ;
} Cube U_colock(){
Cube o ;
for(int i = ;i < ;i++)
o.a[i] = a[i] ;
o.a[] = a[] ;
o.a[] = a[] ;
o.a[] = a[] ;
o.a[] = a[] ;
o.a[] = a[] ;
o.a[] = a[] ;
o.a[] = a[] ;
o.a[] = a[] ;
o.a[] = a[] ;
o.a[] = a[] ;
o.a[] = a[] ;
o.a[] = a[] ;
return o ;
} Cube U_count_colock(){
Cube o ;
for(int i = ;i < ;i++)
o.a[i] = a[i] ;
o.a[]= a[];
o.a[]= a[];
o.a[]= a[];
o.a[]= a[] ;
o.a[]= a[] ;
o.a[] =a[];
o.a[] =a[];
o.a[] =a[];
o.a[] =a[];
o.a[] =a[];
o.a[] =a[];
o.a[] =a[];
return o ;
} Cube F_colock(){
Cube o ;
for(int i = ;i < ;i++)
o.a[i] = a[i] ;
o.a[] = a[] ;
o.a[] = a[] ;
o.a[] = a[] ;
o.a[] = a[] ;
o.a[] = a[] ;
o.a[] = a[] ;
o.a[] = a[] ;
o.a[] = a[] ;
o.a[] = a[] ;
o.a[] = a[] ;
o.a[] = a[] ;
o.a[] = a[] ;
return o ;
} Cube F_count_colock(){
Cube o ;
for(int i = ;i < ;i++)
o.a[i] = a[i] ;
o.a[]= a[];
o.a[]= a[];
o.a[]= a[];
o.a[]= a[] ;
o.a[]= a[] ;
o.a[] =a[];
o.a[] =a[];
o.a[] =a[];
o.a[] =a[];
o.a[] =a[];
o.a[] =a[];
o.a[] =a[];
return o ;
} }; int N ;
int ans ; void dfs(Cube cb ,int step){
Cube o ;
if(step>N)
return ;
if(ans == )
return ; o = cb.F_colock() ;
ans = Max(ans,o.complete_face()) ;
dfs(o,step+) ; o = cb.F_count_colock() ;
ans = Max(ans,o.complete_face()) ;
dfs(o,step+) ; o = cb.R_colock() ;
ans = Max(ans,o.complete_face()) ;
dfs(o,step+) ; o = cb.R_count_colock() ;
ans = Max(ans,o.complete_face()) ;
dfs(o,step+) ; o = cb.U_colock();
ans = Max(ans,o.complete_face()) ;
dfs(o,step+) ; o = cb.U_count_colock() ;
ans = Max(ans,o.complete_face()) ;
dfs(o,step+) ;
} int main(){
Cube now ;
while(scanf("%d",&N)!=EOF){
for(int i = ;i < ;i++)
scanf("%d",&now.a[i]) ;
ans = now.complete_face() ;
dfs(now,) ;
printf("%d\n",ans) ;
}
return ;
}
The 2013 ACM-ICPC Asia Changsha Regional Contest - K的更多相关文章
- Gym - 101981K The 2018 ICPC Asia Nanjing Regional Contest K.Kangaroo Puzzle 暴力或随机
题面 题意:给你1个20*20的格子图,有的是障碍有的是怪,你可以每次指定上下左右的方向,然后所有怪都会向那个方向走, 如果2个怪撞上了,就融合在一起,让你给不超过5w步,让所有怪都融合 题解:我们可 ...
- hduoj 4710 Balls Rearrangement 2013 ACM/ICPC Asia Regional Online —— Warmup
http://acm.hdu.edu.cn/showproblem.php?pid=4710 Balls Rearrangement Time Limit: 6000/3000 MS (Java/Ot ...
- hduoj 4708 Rotation Lock Puzzle 2013 ACM/ICPC Asia Regional Online —— Warmup
http://acm.hdu.edu.cn/showproblem.php?pid=4708 Rotation Lock Puzzle Time Limit: 2000/1000 MS (Java/O ...
- hduoj 4715 Difference Between Primes 2013 ACM/ICPC Asia Regional Online —— Warmup
http://acm.hdu.edu.cn/showproblem.php?pid=4715 Difference Between Primes Time Limit: 2000/1000 MS (J ...
- hduoj 4712 Hamming Distance 2013 ACM/ICPC Asia Regional Online —— Warmup
http://acm.hdu.edu.cn/showproblem.php?pid=4712 Hamming Distance Time Limit: 6000/3000 MS (Java/Other ...
- hduoj 4706 Herding 2013 ACM/ICPC Asia Regional Online —— Warmup
hduoj 4706 Children's Day 2013 ACM/ICPC Asia Regional Online —— Warmup Herding Time Limit: 2000/1000 ...
- hduoj 4707 Pet 2013 ACM/ICPC Asia Regional Online —— Warmup
http://acm.hdu.edu.cn/showproblem.php?pid=4707 Pet Time Limit: 4000/2000 MS (Java/Others) Memory ...
- hduoj 4706 Children's Day 2013 ACM/ICPC Asia Regional Online —— Warmup
http://acm.hdu.edu.cn/showproblem.php?pid=4706 Children's Day Time Limit: 2000/1000 MS (Java/Others) ...
- ACM ICPC Central Europe Regional Contest 2013 Jagiellonian University Kraków
ACM ICPC Central Europe Regional Contest 2013 Jagiellonian University Kraków Problem A: Rubik’s Rect ...
随机推荐
- 通用的业务编码规则设计实现[转:http://www.cnblogs.com/xqin/p/3708367.html]
一.背景 每一个企业应用中不可避免的都会涉及到业务编码规则的问题,比如订单管理系统中的订单编号,比如商品管理系统中的商品编码,比如项目管理系统中的项目编码等等,这一系列的编码都需要管理起来,那么它们的 ...
- Struts2 - 传值
Struts2传值有几种方式: 1)URL parameter 例如配置代码: <action name="login_*" class="com.my.actio ...
- SPOJ #440. The Turtle´s Shortest Path
Coding a Dijkstra is not hard. %70 of my time spent on tackling TLE, as my last post. Dijkstra works ...
- 报错:java.lang.IllegalStateException: Cannot call sendError() after the response has been committed(待解答)
严重: Servlet.service() for servlet [default] in context with path [/20161101-struts2-1] threw excepti ...
- C语言每日一题之No.5
总在想,但凡编程基础正常点,都不至于惨败到这个地步.也像大多数人毕业出来,新鲜的第一份工作,如果做得好还可以略有成就感,做得一般还有提升的空间,但至少不至于像我这样基本没基础的被鄙视得一塌糊涂,被外界 ...
- SVN设置实例
D:\scmserver\SVNROOT\safeControl,该SVN项目下,有erSystem和hcSystem两个项目.现在人员有两种类型的人,一个内部人员,一个是佰钧成人员. 设置要求: 1 ...
- 【转】sql server2005中raiserror的用法
raiserror 是由单词 raise error 组成 raise 增加; 提高; 提升 raiserror 的作用: raiserror 是用于抛出一个错误.[ 以下资料来源于sql ...
- 嵌入式jetty
一.maven依赖 pom配置 <dependency> <groupId>org.eclipse.jetty</groupId> <artifactId&g ...
- 如何实现一个malloc
任何一个用过或学过C的人对malloc都不会陌生.大家都知道malloc可以分配一段连续的内存空间,并且在不再使用时可以通过free释放掉.但是,许多程序员对malloc背后的事情并不熟悉,许多人甚至 ...
- hiho #1014 : Trie树
#1014 : Trie树 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho是一对好朋友,出生在信息化社会的他们对编程产生了莫大的兴趣,他们约定好互相帮助, ...