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 ...
随机推荐
- 《从零开始学Swift》学习笔记(Day 14)——字符串的插入、删除和替换
原创文章,欢迎转载.转载请注明:关东升的博客 对应可变字符串可以插入.删除和替换,String提供了几个方法可以帮助实现这些操作.这些方法如下: splice(_:atIndex:).在索引位置插入字 ...
- 关东升的《iOS实战:图形图像、动画和多媒体卷(Swift版)》上市了
关东升的<iOS实战:图形图像.动画和多媒体卷(Swift版)>上市了 承蒙广大读者的厚爱我的<iOS实战:图形图像.动画和多媒体卷(Swift版)>京东上市了,欢迎广大读者提 ...
- 【Python之路】第十三篇--DOM
文档对象模型(Document Object Model,DOM)是一种用于HTML和XML文档的编程接口.它给文档提供了一种结构化的表示方法,可以改变文档的内容和呈现方式.我们最为关心的是,DOM把 ...
- 【python】-- Ajax
Ajax AJAX,Asynchronous JavaScript and XML (异步的JavaScript和XML),一种创建交互式网页应用的网页开发技术方案. 异步的JavaScript:使用 ...
- 如何搭建一个 Git 版本控制服务端?
Gogs 下载和安装 https://github.com/gogits/gogs # 下载二进制压缩包 不检查服务器证书 root@cheungxiongwei:~# wget --no-check ...
- SQL SERVER临时表的使用
SQL SERVER临时表的使用 drop table #Tmp --删除临时表#Tmpcreate table #Tmp --创建临时表#Tmp( ID int IDENTITY (1 ...
- Django的admin样式丢失【静态文件收集】
在部署完Django项目后,进行admin后台登录发现样式丢失,后台日志显示:js和css文件丢失 解决办法: 配置settings.py如下: #DEBUG打开时,app的静态文件默认从这里读取 S ...
- Insert Buffering
14.5.13.4 Insert Buffering Database applications often insert new rows in the ascending order of the ...
- 003-搭建框架-实现IOC机制
一.实现目标 一种MVC[Model-View-Controller]一种设计模式,进行解耦. /* * 处理客户管理相关请求 */ @Controller public class Customer ...
- F-02 创建财务凭证BAPI
**.获取抬头参数, documentheader **.项目参数 accountgl = lt_acgl"G/L account item accountreceivable = lt_a ...