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 ...
随机推荐
- ubuntu 使用adb shell命令识别android设备
ubuntu 使用adb shell命令配置 在ubuntu下使用adb 命令识别Android设备需配置adb_usb.ini 文件 文件路径: ~/.android/ ,若不存在创建该文件. a ...
- window7 下 安装 apache24(httpd-2.4.10-x86-r2)加 php5.6(php-5.6.4-Win32-VC11-x86)加yaf(php_yaf-2.3.3-5.6-ts-vc11-x86)整合
window7 下 安装 apache24(httpd-2.4.10-x86-r2)加 php5.6(php-5.6.4-Win32-VC11-x86)加yaf(php_yaf-2.3.3-5.6-t ...
- Linux中ftp不能上传文件/目录的解决办法
在linux中不能上传文件或文件夹最多的问题就是权限问题,但有时也不一定是权限问题了,像我就是空间不够用了,下面我来总结一些ftp不能上传文件/目录的解决办法 在排除用户组和权限等问题后,最可能引 ...
- 在网页标题栏上和收藏夹显示网站logo
第一步,准备一个图标制作软件. 首先您必须了解所谓的图标(Icon)是一种特殊的图形文件格式,它是以.ico 作为扩展名.普通的图像设计软件无法使用这种格式,所以您需要到下载一个ico图标工具,本站常 ...
- 【linux】 /etc/shadow 文件
格式:username: passwd: lastchg: min: max: warn: inactive: expire: flag 登录名:加密口令:最后一次修改时间:最小时间间隔:最大时间间隔 ...
- Session和Cookie深度剖析
Session和Cookie的区别 具体来说cookie机制采用的是在客户端保持状态的方案,而session机制采用的是在服务器端保持状态的方案.同时我们也看到,由于采用服务器端保持状态的方案在客户端 ...
- W81安装记录
安装Windows 8.1之前先断网!!! 在x86的WinPE环境中安装Windows 8.1 x64的方法: 1.格式化硬盘的第一主分区C盘,将x64的ISO解压到其他分区里: 2.复制ISO解压 ...
- 【转】SQL SERVER 存储过程中变量的作用域
今天遇到一个很有趣的事情,以前没有注意过,所以记下来. 先来看例子. SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE ...
- 黄聪:解决丢失api-ms-win-crt-runtime-|1-1-0.dll的问题:vc_redist.x64
解决无法启动程序,因计算机中丢失api-ms-win-crt-runtime-|1-1-0.dll的问题 安装:Microsoft Visual C++ 2015 RC Redistributable ...
- C#学习笔记三: C#2.0泛型 可控类型 匿名方法和迭代器
前言 C#1.0的委托特性使方法作为其他方法的参数来传递,而C#2.0 中提出的泛型特性则使类型可以被参数化,从而不必再为不同的类型提供特殊版本的实现方法.另外C#2.0还提出了可空类型,匿名方法和迭 ...