题意:给定n个立方体,让你重新涂尽量少的面,使得所有立方体都相同。

析:暴力求出每一种姿态,然后枚举每一种立方体的姿态,求出最少值。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#define debug() puts("++++");
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-5;
const int maxn = 20000 + 10;
const int mod = 1e6 + 10;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
const int dice24[24][6] = {
{2, 1, 5, 0, 4, 3},
{2, 0, 1, 4, 5, 3},
{2, 4, 0, 5, 1, 3},
{2, 5, 4, 1, 0, 3},
{4, 2, 5, 0, 3, 1},
{5, 2, 1, 4, 3, 0},
{1, 2, 0, 5, 3, 4},
{0, 2, 4, 1, 3, 5},
{0, 1, 2, 3, 4, 5},
{4, 0, 2, 3, 5, 1},
{5, 4, 2, 3, 1, 0},
{1, 5, 2, 3, 0, 4},
{5, 1, 3, 2, 4, 0},
{1, 0, 3, 2, 5, 4},
{0, 4, 3, 2, 1, 5},
{4, 5, 3, 2, 0, 1},
{1, 3, 5, 0, 2, 4},
{0, 3, 1, 4, 2, 5},
{4, 3, 0, 5, 2, 1},
{5, 3, 4, 1, 2, 0},
{3, 4, 5, 0, 1, 2},
{3, 5, 1, 4, 0, 2},
{3, 1, 0, 5, 4, 2},
{3, 0, 4, 1, 5, 2},
}; map<string, int> mp;
int dice[10][10];
int ans;
int r[10]; int getId(const string &s){
if(mp.count(s)) return mp[s];
return mp[s] = mp.size();
}
int color[10][10]; void judge(){
for(int i = 0; i < n; ++i)
for(int j = 0; j < 6; ++j) color[i][dice24[r[i]][j]] = dice[i][j];
int tot = 0;
for(int i = 0; i < 6; ++i){
int cnt[30];
memset(cnt, 0, sizeof cnt);
int mmax = 0;
for(int j = 0; j < n; ++j) mmax = max(mmax, ++cnt[color[j][i]]);
tot += n - mmax;
}
ans = min(ans, tot);
} void dfs(int d){
if(d == n){ judge(); return ; }
for(int i = 0; i < 24; ++i){
r[d] = i;
dfs(d+1);
}
} int main(){
while(cin >> n && n){
mp.clear();
string s;
for(int i = 0; i < n; ++i)
for(int j = 0; j < 6; ++j){
cin >> s;
dice[i][j] = getId(s);
}
ans = n * 6;
r[0] = 0;
dfs(1);
cout << ans << endl;
}
return 0;
}

UVaLive 3401 Colored Cubes (暴力)的更多相关文章

  1. UVALive 3401 - Colored Cubes 旋转 难度: 1

    题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

  2. UVALive - 3401 Colored Cubes

    好久没写解题回顾了.主要是没什么时间,但是还是一直在刷题,图论刷了70%的知识点,不过感觉长进不是很大,所以觉得还是得一步步来,最近还是先从刘汝佳大白书把前面基础章节刷完然后再决定以后的训练方式吧. ...

  3. LA 3401 - Colored Cubes

    解题报告:有n(1<=n<=4)个立方体,每个立方体的每一个面涂有一种颜色,现在要将这些立方体的某些面的颜色重新涂一下,使得这n个立方体旋转到某一种状态下,对应的面的颜色都相同. 这题可以 ...

  4. 1352 - Colored Cubes (枚举方法)

    There are several colored cubes. All of them are of the same size but they may be colored differentl ...

  5. UVA 10733 - The Colored Cubes(Ploya)

    UVA 10733 - The Colored Cubes 题目链接 题意:一个立方体.n种颜色,问能涂成多少不同立方体 思路:Ploya求解,正方体相应24种不同旋转一一计算出循环个数就可以.和 U ...

  6. POJ2741 Colored Cubes

    Description There are several colored cubes. All of them are of the same size but they may be colore ...

  7. Gym 100299C && UVaLive 6582 Magical GCD (暴力+数论)

    题意:给出一个长度在 100 000 以内的正整数序列,大小不超过 10^ 12.求一个连续子序列,使得在所有的连续子序列中, 它们的GCD值乘以它们的长度最大. 析:暴力枚举右端点,然后在枚举左端点 ...

  8. poj1543-Perfect Cubes(暴力)

    水题:求n^3 =  a^3 + b^3 + c^3 ;暴力即可 #include<iostream> using namespace std; int main(){ int n ; c ...

  9. 【poj2741】 Colored Cubes

    http://poj.org/problem?id=2741 (题目链接) 题意 给出n个骰子,每一面都有一种颜色,问最少更改多少个面的颜色可以使所有骰子通过旋转后完全相同. solution 迷之d ...

随机推荐

  1. Activiti Model Editor组件

    通过Activiti Modeler架构图可知,Activiti Explorer采用的是Vaadin框架. Vaadin 是一种 Java Web 应用程序的开发框架, 其设计目标是便利地创建和维护 ...

  2. Solidworks如何绘制标准螺纹线

    1 绘制螺旋线,螺距为0.5mm,圈数为15,起始角度为0°.   2                

  3. SolidEdge如何自动标注尺寸

    1 工具-尺寸-关系助手(必须在编辑草图轮廓状态下,如果你的草图不可编辑,则没有这些选项)   2 框选要自动标注尺寸的东西,这些东西立即变为黄色,然后打对勾   3 选择横纵坐标尺寸原点(其实就是为 ...

  4. python web框架企业实战具体解释(第六期)\第三课时-ajax&amp;jquery&amp;webpy

    main.py __author__ = 'Liao' import web import time urls = ( '/gettime','gettime', '/(.*)', 'hello' ) ...

  5. angularJS---自己定义过滤器

    AngularJS还有一个特点就是提供了过滤器.能够通过操作UNIX下管道的方式,操作数据结果. 通过使用管道.能够便于双向的数据绑定中视图的展现. 过滤器在处理过程中,将数据变成新的格式.并且能够使 ...

  6. ok6410[000] 搭建裸机开发环境

    1.安装交叉工具链arm-linux-gcc-4.3.2 先把这个工具复制到rhat系统中[rhel-server-6.3-i386-dvd.iso] 解压arm-linux-gcc-4.3.2到一个 ...

  7. AML LCD debuged

    root@k101:/ # cat /sys/class/lcd/debug                                          Usage:     echo basi ...

  8. EF中 Code-First 方式的数据库迁移

    原文链接:http://www.c-sharpcorner.com/UploadFile/3d39b4/code-first-migrations-with-entity-framework/ 系列目 ...

  9. BZOJ 3992: [SDOI2015]序列统计 快速幂+NTT(离散对数下)

    3992: [SDOI2015]序列统计 Description 小C有一个集合S,里面的元素都是小于M的非负整数.他用程序编写了一个数列生成器,可以生成一个长度为N的数列,数列中的每个数都属于集合S ...

  10. javascript event事件兼容性处理

    ie 6-8支持event事件,ff浏览器不支持 获取鼠标点击位置的坐标 document.onclick = function(){ alert(event.clientX +"-&quo ...