UVALive - 3401 Colored Cubes 枚举
2015-02-24 12:29
399 查看
题目大意:有n个带颜色的立方体,每个面都涂有一种颜色,要求重新涂尽量少的面,使得所有的立方体都相同,两个立方体相同的含义是:存在一种旋转方式,使得两个立方体对应的颜色相同
解题思路:枚举n个立方体的每种旋转后的状态,然后再统计需要重新涂的面
解题思路:枚举n个立方体的每种旋转后的状态,然后再统计需要重新涂的面
#include<cstdio> #include<cstring> #include<algorithm> #include<vector> #include<string> using namespace std; const int dice[24][6] = {{0,1,2,3,4,5},{0,3,1,4,2,5},{0,2,4,1,3,5},{0,4,3,2,1,5},{1,2,0,5,3,4},{1,5,2,3,0,4},{1,0,3,2,5,4},{1,3,5,0,2,4},{2,1,5,0,4,3},{2,0,1,4,5,3},{2,4,0,5,1,3},{2,5,4,1,0,3},{3,4,5,0,1,2},{3,5,1,4,0,2},{3,1,0,5,4,2},{3,0,4,1,5,2},{4,2,5,0,3,1},{4,0,2,3,5,1},{4,5,3,2,0,1},{4,3,0,5,2,1},{5,2,1,4,3,0},{5,4,2,3,1,0},{5,1,3,2,4,0},{5,3,4,1,2,0}}; #define maxn 10 int start[maxn][6], end[maxn][6], r[maxn], num , N , MIN, num_color[maxn*6]; vector<string> color; int change(const char *t) { string tmp = (string) t; int size = color.size(); for(int i = 0; i < size; i++) if(tmp == color[i]) return i; color.push_back(tmp); return size; } void check() { for(int i = 0; i < N; i++) for(int j = 0; j < 6; j++) end[i][dice[r[i]][j]] = start[i][j]; int sum = 0; for(int i = 0; i < 6; i++) { memset(num_color,0,sizeof(num_color)); int MAX = 0; for(int j = 0; j < N; j++) MAX = max(MAX,++num_color[end[j][i]]); sum += N - MAX; } MIN = min(MIN,sum); } void dfs(int cur) { if(cur == N) check(); else for(int i = 0; i < 24; i++) { r[cur] = i; dfs(cur+1); } } int main() { while(scanf("%d",&N) == 1 && N) { color.clear(); char temp[30]; for(int i = 0; i < N; i++) for(int j = 0; j < 6; j++) { scanf("%s",temp); start[i][j] = change(temp); } MIN = 6 * N; dfs(1); printf("%d\n",MIN); } return 0; }
相关文章推荐
- UVALIVE 3401 Colored Cubes
- UVALive 3401 Colored Cubes
- UVALive 3401 Colored Cubes
- uvalive 3401 poj 2741 Colored Cubes
- UVALive - 3401 Colored Cubes
- UVALive - 3401 Colored Cubes
- uvaLive 3401 Colored Cubes 暴力
- UVALive - 3401 Colored Cubes
- UVALive 3953 Strange Billboard (状态压缩+枚举)
- UVALive 6692 Lucky Number (思路 + 枚举)
- uva 1352 - Colored Cubes(枚举)
- UVALive 6269 Digital Clock --枚举,模拟
- UVALive 3401
- uvalive4836(枚举)
- UVALive 4794 Sharing Chocolate(状压,枚举子集)
- Tour Belt [UVALive 4848] 并查集+枚举边长
- UVALive 6659 Dromicpalin Substrings (递推 + 暴力枚举)
- UVALive 6092 Catching Shade in Flatland --枚举+几何计算
- UVALive - 4856 OmniGravity(哈希+枚举)
- UVALive 6092 Catching Shade in Flatland --枚举+几何计算