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. POJ3090

    Visible Lattice Points Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7094   Accepted: ...

  2. maven实现项目热部署

    1.Tomcat的配置 我们需要实现热部署,自然就需要通过maven操作tomcat,所以就需要maven取得操作tomcat的权限,现在这一步就是配置tomcat的可操作权限. 在tomcat的安装 ...

  3. shell中${}的使用

    1. 截断功能${file#*/}:       拿掉第一条/及其左边的字符串:dir1/dir2/dir3/my.file.txt${file##*/}:    拿掉最后一条/及其左边的字符串:my ...

  4. client-server model peer-to-peer architecture 主从式架构

    w https://zh.wikipedia.org/wiki/主从式架构 主从式架构 (Client–server model) 或客户端-服务器(Client/Server)结构简称C/S结构,是 ...

  5. JS续

    JS中的事件 [JS中的事件分类] * 1.鼠标事件: * click/dbclick/mouseover/mouseout/mousemove/mousedown/mouseup * * 2.键盘事 ...

  6. mysql学习笔记—常用sql函数

    SQL 拥有很多可用于计数和计算的内建函数. SQL Aggregate 函数 SQL Aggregate 函数计算从列中取得的值,返回一个单一的值. 有用的 Aggregate 函数: AVG() ...

  7. python面向对象之 封装(Day25)

    封装: 隐藏对象的属性和实现细节,仅对外提供公共访问方式 好处:1.将变化隔离 2.便于使用 3.提高复用性 4.提高安全性 封装原则: 1.将不需要对外提供的内容隐藏起来 2.把属性都隐藏,提供公共 ...

  8. set去重,session,cookie c#与python 对比

    端口,发送请求进行监听,然后处理 session 是存储在服务器端的数据,靠sessionId来验证获取信息,没有大小和类型限制, cookie   是存储在客户端的数据,可以长期使用,有面临被获取的 ...

  9. JavaScript:学习笔记(3)——正则表达式的应用

    JavaScript:正则表达式的应用 应用正则表达式对象RegExp 创建正则表达式 JavaScript中使用RegExp对象来表述一个正则表达式.使用正则表达式之前首先要创建一个RegExp对象 ...

  10. PAT 天梯赛 L2-021. 点赞狂魔 【水】

    题目链接 https://www.patest.cn/contests/gplt/L2-021 题意 给出一个若干个人名,后面给出点赞的总数,以及每个赞的标签类型,输出前三个点赞狂魔,按标签类型不同数 ...