Description

There are several colored cubes. All of them are of the same size but they may be colored differently. Each face of these cubes has a single color. Colors of distinct faces of a cube may or may not be the same.
Two cubes are said to be identically colored if some suitable
rotations of one of the cubes give identical looks to both of the cubes.
For example, two cubes shown in Figure 2 are identically colored. A set
of cubes is said to be identically colored if every pair of them are
identically colored.

A cube and its mirror image are not necessarily identically colored.
For example, two cubes shown in Figure 3 are not identically colored.

You can make a given set of cubes identically colored by repainting
some of the faces, whatever colors the faces may have. In Figure 4,
repainting four faces makes the three cubes identically colored and
repainting fewer faces will never do.

Your task is to write a program to calculate the minimum number of
faces that needs to be repainted for a given set of cubes to become
identically colored.

Input

The
input is a sequence of datasets. A dataset consists of a header and a
body appearing in this order. A header is a line containing one positive
integer n and the body following it consists of n lines. You can assume
that 1 <= n <= 4. Each line in a body contains six color names
separated by a space. A color name consists of a word or words connected
with a hyphen (-). A word consists of one or more lowercase letters.
You can assume that a color name is at most 24-characters long including
hyphens.

A dataset corresponds to a set of colored cubes. The integer n
corresponds to the number of cubes. Each line of the body corresponds to
a cube and describes the colors of its faces. Color names in a line is
ordered in accordance with the numbering of faces shown in Figure 5. A
line

    color1 color2 color3 color4 color5 color6

corresponds to a cube colored as shown in Figure 6.

The end of the input is indicated by a line containing a single zero. It is not a dataset nor a part of a dataset.





Output

For
each dataset, output a line containing the minimum number of faces that
need to be repainted to make the set of cubes identically colored.

Sample Input

3
scarlet green blue yellow magenta cyan
blue pink green magenta cyan lemon
purple red blue yellow cyan green
2
red green blue yellow magenta cyan
cyan green blue yellow magenta red
2
red green gray gray magenta cyan
cyan green gray gray magenta red
2
red green blue yellow magenta cyan
magenta red blue yellow cyan green
3
red green blue yellow magenta cyan
cyan green blue yellow magenta red
magenta red blue yellow cyan green
3
blue green green green green blue
green blue blue green green green
green green green green green sea-green
3
red yellow red yellow red yellow
red red yellow yellow red yellow
red red red red red red
4
violet violet salmon salmon salmon salmon
violet salmon salmon salmon salmon violet
violet violet salmon salmon violet violet
violet violet violet violet salmon salmon
1
red green blue yellow magenta cyan
4
magenta pink red scarlet vermilion wine-red
aquamarine blue cyan indigo sky-blue turquoise-blue
blond cream chrome-yellow lemon olive yellow
chrome-green emerald-green green olive vilidian sky-blue
0

Sample Output

4
2
0
0
2
3
4
4
0
16
 
 
正解:搜索
解题报告:
  今天考试考了这道题,考场上调试了一会儿,毕竟是半码农题。。。
  考虑对于每一个立方体,如果我确立了一个面为顶面,则还可选择相邻的四个面中的一个,则可唯一确定一个立方体,那么一共有6*4=24种状态。一共有4个立方体,那么显然我只需要保持第一个不动,剩下三个枚举哪种状态就可以了。然后我们再对于四个确立好状态的立方体每个面贪心地染色,可以得出答案。
  对于题目给的颜色名称我直接用map映射到int上去了,然后可以直接编号。
 
 
 //It is made by jump~
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <ctime>
#include <vector>
#include <queue>
#include <map>
#include <set>
#ifdef WIN32
#define OT "%I64d"
#else
#define OT "%lld"
#endif
using namespace std;
typedef long long LL;
const int MAXN = ;
int biao[][]={
{,,,,,},{,,,,,},{,,,,,},{,,,,,},
{,,,,,},{,,,,,},{,,,,,},{,,,,,},
{,,,,,},{,,,,,},{,,,,,},{,,,,,},
{,,,,,},{,,,,,},{,,,,,},{,,,,,},
{,,,,,},{,,,,,},{,,,,,},{,,,,,},
{,,,,,},{,,,,,},{,,,,,},{,,,,,},
};
int n;
int paint[MAXN][];
int ans,ecnt;
int rotat[MAXN],color[MAXN][];
string ch;
int col_cnt[MAXN*];//每种颜色
map<string,int>mp; inline int getint()
{
int w=,q=;
char c=getchar();
while((c<'' || c>'') && c!='-') c=getchar();
if (c=='-') q=, c=getchar();
while (c>='' && c<='') w=w*+c-'', c=getchar();
return q ? -w : w;
} inline void dfs(int d){
if(d==n){
for(int i=;i<n;i++) for(int j=;j<;j++) color[i][ biao[ rotat[i] ][j] ]=paint[i][j]; int tot=;
for(int j=;j<;j++) {//枚举每个面
memset(col_cnt,,sizeof(col_cnt));
int now=;
for(int i=;i<n;i++){//考虑每个立方体
col_cnt[ color[i][j] ]++;
now=max(now,col_cnt[color[i][j]]);
}
tot+=n-now;
}
ans=min(ans,tot); return ;
}
for(int i=;i<;i++) rotat[d]=i,dfs(d+);
} inline void work(){
while() {
n=getint(); if(n==) break;
for(int i=;i<n;i++)
for(int j=;j<;j++) {
cin>>ch;
if(mp[ch]!=) paint[i][j]=mp[ch];
else { mp[ch]=++ecnt; paint[i][j]=mp[ch]; }
}
ans=n*;rotat[]=;//第一个立方体固定不动
dfs(); printf("%d\n",ans);
}
} int main()
{
work();
return ;
}

POJ2741 Colored Cubes的更多相关文章

  1. 1352 - Colored Cubes (枚举方法)

    There are several colored cubes. All of them are of the same size but they may be colored differentl ...

  2. UVA 10733 - The Colored Cubes(Ploya)

    UVA 10733 - The Colored Cubes 题目链接 题意:一个立方体.n种颜色,问能涂成多少不同立方体 思路:Ploya求解,正方体相应24种不同旋转一一计算出循环个数就可以.和 U ...

  3. 【poj2741】 Colored Cubes

    http://poj.org/problem?id=2741 (题目链接) 题意 给出n个骰子,每一面都有一种颜色,问最少更改多少个面的颜色可以使所有骰子通过旋转后完全相同. solution 迷之d ...

  4. UVALive 3401 - Colored Cubes 旋转 难度: 1

    题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

  5. LA 3401 - Colored Cubes

    解题报告:有n(1<=n<=4)个立方体,每个立方体的每一个面涂有一种颜色,现在要将这些立方体的某些面的颜色重新涂一下,使得这n个立方体旋转到某一种状态下,对应的面的颜色都相同. 这题可以 ...

  6. UVALive - 3401 Colored Cubes

    好久没写解题回顾了.主要是没什么时间,但是还是一直在刷题,图论刷了70%的知识点,不过感觉长进不是很大,所以觉得还是得一步步来,最近还是先从刘汝佳大白书把前面基础章节刷完然后再决定以后的训练方式吧. ...

  7. 【codeforces 1025E】Colored Cubes 【构造】

    题意 有一个n*n的棋盘和m个棋子,每个棋子有一个初始位置和一个目标位置,每次移动只能选择一个棋子移动到他相邻的格子,并且花费一秒钟.请你找出一个移动的方法,使得在10800步内将所有棋子移动到目标位 ...

  8. uva 10733 The Colored Cubes<polya定理>

    链接:http://uva.onlinejudge.org/external/107/10733.pdf 题意: N 种颜色可以涂成多少种立方体~ 思路: 使正六面体保持不变的运动群总共有: 1.不变 ...

  9. UVaLive 3401 Colored Cubes (暴力)

    题意:给定n个立方体,让你重新涂尽量少的面,使得所有立方体都相同. 析:暴力求出每一种姿态,然后枚举每一种立方体的姿态,求出最少值. 代码如下: #pragma comment(linker, &qu ...

随机推荐

  1. HDU4781(2013成都站A题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4781 题目大意:给你n个点m条边,要求你构造一个符合条件的有向联通图(若无法构造输出-1,否则输出任意 ...

  2. poj1840

    Eqs Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 15133   Accepted: 7426 Description ...

  3. poj3159

    Candies Time Limit: 1500MS   Memory Limit: 131072K Total Submissions: 28133   Accepted: 7766 Descrip ...

  4. 母版页改变被嵌套的页面中的控件ID的解决方法

    使用过模板页的朋友都会很纳闷,怎么页面的用js通过getElementById(“id”):找不到对象.查看了页面源代码才发现,原来控件的ID变了,这是母版页导致的.因为母版页怕母版页本身页面中的控件 ...

  5. 段合并 segments merge 被删除的文档的删除时间

    2.5 段合并 每个索引分为多个“写一次,读多次”的段 write once and read many times  segments 建立索引时,一个段写入磁盘以后就不能更新:被删除的文档的信息存 ...

  6. window子对象

    Window 子对象 (1)Location 对象 Location 对象包含有关当前 URL(统一资源定位符) 的信息.(Uniform Resource Location) Location 对象 ...

  7. EChars文档

    http://echarts.baidu.com/echarts2/doc/doc.html#SeriesMap http://echarts.baidu.com/option.html

  8. python面试题(七)

    1 什么是局域网.广域网.城域网? ①局域网LAN(Local Area Network):一般指覆盖范围在10公里以内,一座楼房或一个单位内部的网络.由于传输距离直接影响传输速度,因此,局域网内的通 ...

  9. win7安装laravel

    使用Packagist 镜像 建立一个composer.json文件,内容如下: { "name": "laravel/laravel", "desc ...

  10. Js前台页面搜索

    $("#filter").on("keyup",function(){$(".aimed_list").hide().filter(&quo ...