POJ2741 Colored Cubes

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上去了,然后可以直接编号。
 
 
 1 //It is made by jump~
 2 #include <iostream>
 3 #include <cstdlib>
 4 #include <cstring>
 5 #include <cstdio>
 6 #include <cmath>
 7 #include <algorithm>
 8 #include <ctime>
 9 #include <vector>
10 #include <queue>
11 #include <map>
12 #include <set>
13 #ifdef WIN32   
14 #define OT "%I64d"
15 #else
16 #define OT "%lld"
17 #endif
18 using namespace std;
19 typedef long long LL;
20 const int MAXN = 70;
21 int biao[250][60]={
22     {0,1,2,3,4,5},{0,2,4,1,3,5},{0,4,3,2,1,5},{0,3,1,4,2,5},
23     {1,2,0,5,3,4},{1,5,2,3,0,4},{1,0,3,2,5,4},{1,3,5,0,2,4},
24     {2,1,5,0,4,3},{2,0,1,4,5,3},{2,4,0,5,1,3},{2,5,4,1,0,3},
25     {3,4,5,0,1,2},{3,5,1,4,0,2},{3,1,0,5,4,2},{3,0,4,1,5,2},
26     {4,0,2,3,5,1},{4,2,5,0,3,1},{4,5,3,2,0,1},{4,3,0,5,2,1},
27     {5,2,1,4,3,0},{5,1,3,2,4,0},{5,4,2,3,1,0},{5,3,4,1,2,0},    
28 };
29 int n;
30 int paint[MAXN][60];
31 int ans,ecnt;
32 int rotat[MAXN],color[MAXN][60];
33 string ch;
34 int col_cnt[MAXN*6];//每种颜色
35 map<string,int>mp;
36 
37 inline int getint()
38 {
39        int w=0,q=0;
40        char c=getchar();
41        while((c<'0' || c>'9') && c!='-') c=getchar();
42        if (c=='-')  q=1, c=getchar();
43        while (c>='0' && c<='9') w=w*10+c-'0', c=getchar();
44        return q ? -w : w;
45 }
46 
47 inline void dfs(int d){
48     if(d==n){ 
49     for(int i=0;i<n;i++) for(int j=0;j<6;j++) color[i][ biao[ rotat[i] ][j] ]=paint[i][j];
50     
51     int tot=0;
52     for(int j=0;j<6;j++) {//枚举每个面
53         memset(col_cnt,0,sizeof(col_cnt));
54         int now=0;
55         for(int i=0;i<n;i++){//考虑每个立方体
56         col_cnt[ color[i][j] ]++;
57         now=max(now,col_cnt[color[i][j]]);
58         }
59         tot+=n-now;
60     }
61     ans=min(ans,tot);
62 
63     return ; 
64     } 
65     for(int i=0;i<24;i++) rotat[d]=i,dfs(d+1);
66 }
67 
68 inline void work(){
69     while(1) {
70     n=getint(); if(n==0) break;    
71     for(int i=0;i<n;i++) 
72         for(int j=0;j<6;j++) {        
73         cin>>ch;
74         if(mp[ch]!=0) paint[i][j]=mp[ch];
75         else { mp[ch]=++ecnt; paint[i][j]=mp[ch]; }        
76         }
77     ans=n*6;rotat[0]=0;//第一个立方体固定不动
78     dfs(1);    printf("%d\n",ans);
79     }
80 }
81 
82 int main()
83 {
84   work();
85   return 0;
86 }

 

转载于:https://www.cnblogs.com/ljh2000-jump/p/5753581.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
校园悬赏任务平台对字典管理、论坛管理、任务资讯任务资讯公告管理、接取用户管理、任务管理、任务咨询管理、任务收藏管理、任务评价管理、任务订单管理、发布用户管理、管理员管理等进行集中化处理。经过前面自己查阅的网络知识,加上自己在学校课堂上学习的知识,决定开发系统选择小程序模式这种高效率的模式完成系统功能开发。这种模式让操作员基于浏览器的方式进行网站访问,采用的主流的Java语言这种面向对象的语言进行校园悬赏任务平台程序的开发,在数据库的选择上面,选择功能强大的Mysql数据库进行数据的存放操作。校园悬赏任务平台的开发让用户查看任务信息变得容易,让管理员高效管理任务信息。 校园悬赏任务平台具有管理员角色,用户角色,这几个操作权限。 校园悬赏任务平台针对管理员设置的功能有:添加并管理各种类型信息,管理用户账户信息,管理任务信息,管理任务资讯公告信息等内容。 校园悬赏任务平台针对用户设置的功能有:查看并修改个人信息,查看任务信息,查看任务资讯公告信息等内容。 系统登录功能是程序必不可少的功能,在登录页面必填的数据有两项,一项就是账号,另一项数据就是密码,当管理员正确填写并提交这二者数据之后,管理员就可以进入系统后台功能操作区。项目管理页面提供的功能操作有:查看任务,删除任务操作,新增任务操作,修改任务操作。任务资讯公告信息管理页面提供的功能操作有:新增任务资讯公告,修改任务资讯公告,删除任务资讯公告操作。任务资讯公告类型管理页面显示所有任务资讯公告类型,在此页面既可以让管理员添加新的任务资讯公告信息类型,也能对已有的任务资讯公告类型信息执行编辑更新,失效的任务资讯公告类型信息也能让管理员快速删除。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值