POJ2741 Colored Cubes
Description
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
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
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
//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的更多相关文章
- 1352 - Colored Cubes (枚举方法)
There are several colored cubes. All of them are of the same size but they may be colored differentl ...
- UVA 10733 - The Colored Cubes(Ploya)
UVA 10733 - The Colored Cubes 题目链接 题意:一个立方体.n种颜色,问能涂成多少不同立方体 思路:Ploya求解,正方体相应24种不同旋转一一计算出循环个数就可以.和 U ...
- 【poj2741】 Colored Cubes
http://poj.org/problem?id=2741 (题目链接) 题意 给出n个骰子,每一面都有一种颜色,问最少更改多少个面的颜色可以使所有骰子通过旋转后完全相同. solution 迷之d ...
- UVALive 3401 - Colored Cubes 旋转 难度: 1
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...
- LA 3401 - Colored Cubes
解题报告:有n(1<=n<=4)个立方体,每个立方体的每一个面涂有一种颜色,现在要将这些立方体的某些面的颜色重新涂一下,使得这n个立方体旋转到某一种状态下,对应的面的颜色都相同. 这题可以 ...
- UVALive - 3401 Colored Cubes
好久没写解题回顾了.主要是没什么时间,但是还是一直在刷题,图论刷了70%的知识点,不过感觉长进不是很大,所以觉得还是得一步步来,最近还是先从刘汝佳大白书把前面基础章节刷完然后再决定以后的训练方式吧. ...
- 【codeforces 1025E】Colored Cubes 【构造】
题意 有一个n*n的棋盘和m个棋子,每个棋子有一个初始位置和一个目标位置,每次移动只能选择一个棋子移动到他相邻的格子,并且花费一秒钟.请你找出一个移动的方法,使得在10800步内将所有棋子移动到目标位 ...
- uva 10733 The Colored Cubes<polya定理>
链接:http://uva.onlinejudge.org/external/107/10733.pdf 题意: N 种颜色可以涂成多少种立方体~ 思路: 使正六面体保持不变的运动群总共有: 1.不变 ...
- UVaLive 3401 Colored Cubes (暴力)
题意:给定n个立方体,让你重新涂尽量少的面,使得所有立方体都相同. 析:暴力求出每一种姿态,然后枚举每一种立方体的姿态,求出最少值. 代码如下: #pragma comment(linker, &qu ...
随机推荐
- Cocos2d-x Lua中多场景切换生命周期
在多个场景切换时候,场景的生命周期会更加复杂.这一节我们介绍一下场景切换生命周期.多个场景切换时候分为几种情况:情况1,使用pushScene函数从实现GameScene场景进入SettingScen ...
- #1589 : 回文子串的数量(Manacher)
#1589 : 回文子串的数量 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 给定一个字符串S,请统计S的所有|S| * (|S| + 1) / 2个子串中(首尾位置不 ...
- Echarts-雷达图
// 显示能力雷达图 $(".company .grade").hover(function () { $(".powerChart").show(); var ...
- h5-localStorage实现缓存ajax请求数据
使用背景:要实现每次鼠标hover“能力雷达”,则显示能力雷达图(通过ajax请求数据实现雷达图数据显示),所以每次hover都去请求ajax会影响性能,因此这里要用到本地缓存. 实现: 此处是通过传 ...
- 常用代码页与BOM
常用代码页:CP437 IBM437 OEM United StatesCP1252表示West European LatinCP932 日本CP949 韩国CP936表示GBK中文编码CP54936 ...
- js四则运算符
只有当加法运算时,其中一方是字符串类型,就会把另一个也转为字符串类型.其他运算只要其中一方是数字,那么另一方就转为数字.并且加法运算会触发三种类型转换:将值转换为原始值,转换为数字,转换为字符串. & ...
- JS+PHP瀑布流效果(二)
<!-- 加载商品 --><script> //用户拖动滚动条,达到底部时ajax加载一次数据 var loading = $("#loading&quo ...
- MySQL中Btree和Hash的局限小结
在索引中,Btree索引和Hash索引的局限性,在这里粗略罗列一下 1 Btree局限 B-树中的节点都是顺序存储的,所以可以利用索引进行查找(找某些值),也可以对查询结果进行ORDER BY(注意O ...
- nodejs从服务器获取数据
// 从服务器获取数据 request('http://192.168.1.7:8080/getDemo', function(error, response, body) { console.log ...
- T-SQL怎样提高数据库性能
总结: 1.书写问题 2.表连接方式 3.索引的抉择 4.执行计划之参数嗅探 5.子查询与表连接的效率 6.临时表.CTE.表变量的选择 7.常用sp与select的缓存命中 8.锁(善用nolock ...