白书第一章例题8

好麻烦!

正方体每面编号为0-5,那么根据顶点和正面,就能确定形态。一共6*4=24种形态。

P[i]表示编号i所在位置。比如P[1]=3,表示第二面转到了第四面。

就可以表示出所有形态。

这时候可以手算或者写个函数找出所有形态。

注意选择函数计算,要放到main外面,方便调。

注意到每个形态都可以由基本姿态左旋上旋得到,而左上旋很接近,就可以模块化了。

然后枚举染色情况。取一个正方体不转(作为参考系,套路了),然后枚举其他三个的情况,然后分别计算6个面。

#include <iostream>
#include <cstring>
#include <vector>
#include <string> using namespace std; const int maxn = ;
int N,dice[maxn][],ans;
vector<string> names;
int dice24[][];
int r[maxn],color[maxn][]; int Left[] = {,,,,,};
int Up[] = {,,,,,};
void rot(int T[],int p[])
{
int q[];
memcpy(q,p,sizeof(q));
for (int i = ; i < ; i++)
p[i] = T[q[i]];
} void enumerate()
{
int p0[] = {,,,,,};
int times = ;
for (int i = ; i < ; i++)
{
int p[];
memcpy(p,p0,sizeof(p0));
if (i == ) rot(Up,p);
if (i == )
{
rot(Left,p);
rot(Up,p);
}
if (i ==)
{
rot(Up,p);
rot(Up,p);
}
if (i == )
{
rot(Left,p);
rot(Left,p);
rot(Left,p);
rot(Up,p);
}
if (i == )
{
rot(Left,p);
rot(Left,p);
rot(Up,p);
}
for (int j = ; j < ; j++)
{
for (int k = ; k < ; k++)
{
dice24[times][k] = p[k];
}
rot(Left,p);
times++;
}
}
} int get_ID(string name)
{
int n = names.size();
for (int i = ; i < n; i++)
{
if (names[i] == name)
return i;
}
names.push_back(name);
return n;
} void check()
{
for (int i = ; i < N; i++)
{
for (int j = ; j < ; j++)
{
color[i][dice24[r[i]][j]] = dice[i][j];
} }
int tot = ;
for (int j = ; j < ; j++)
{
int cnt[maxn*];
memset(cnt,,sizeof(cnt));
int maxface = ;
for (int i = ; i < N; i++)
{
maxface = max(maxface,++cnt[color[i][j]]);
}
tot += N - maxface;
}
ans = min(ans,tot);
} void dfs(int d)
{
if (d == N) check();
else
{
for (int i = ; i < ; i++)
{
r[d] = i;
dfs(d+);
}
}
} int main()
{
enumerate();
while (cin>>N && N)
{
names.clear();
for (int i = ; i < N; i++)
{
for (int j = ; j < ; j++)
{
string name;
cin>>name;
dice[i][j] = get_ID(name);
}
}
ans = N*;
r[] = ;
dfs();
cout<<ans<<endl;
}
return ;
}

uva1352 Colored Cubes LA3401的更多相关文章

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

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

  2. UVA 10733 - The Colored Cubes(Ploya)

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

  3. POJ2741 Colored Cubes

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

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

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

  5. 【poj2741】 Colored Cubes

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

  6. LA 3401 - Colored Cubes

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

  7. UVALive - 3401 Colored Cubes

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

  8. 【codeforces 1025E】Colored Cubes 【构造】

    题意 有一个n*n的棋盘和m个棋子,每个棋子有一个初始位置和一个目标位置,每次移动只能选择一个棋子移动到他相邻的格子,并且花费一秒钟.请你找出一个移动的方法,使得在10800步内将所有棋子移动到目标位 ...

  9. uva 10733 The Colored Cubes<polya定理>

    链接:http://uva.onlinejudge.org/external/107/10733.pdf 题意: N 种颜色可以涂成多少种立方体~ 思路: 使正六面体保持不变的运动群总共有: 1.不变 ...

随机推荐

  1. codevs 等差数列

    1006 等差数列  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解       题目描述 Description 给定n(1<=n<=100) ...

  2. MYSQL数据库学习----查询

    查询语句是MYSQL数据库中用到的最多的语句. 查询语句分为几种 单表查询 集合函数查询 连接查询 子查询 合并查询 正则表达式查询 一:单表查询 SELECT 属性 FROM 表名 [WHERE 查 ...

  3. (二十四)权限控制(粗粒度)-通过filter

    扩展:权限控制(粗粒度)-通过filter 过滤器编写步骤: 1.编写一个类 实现filter接口 重写方法 2.编写配置文件 <filter> <filter-mapping> ...

  4. mysql5.7根据.frm和.ibd文件恢复表结构和数据

    一.恢复表结构 1.环境:Windows .mysql5.7:首先创建一个数据库,可以通过navicat来创建:     2.使用当前创建的数据库:use ww; 3.随意创建一张表,但是这张表的名字 ...

  5. ASP.NET Core MVC 2.x 全面教程_ASP.NET Core MVC 14. ASP.NET Core Identity 入门

    默认的身份认证好授权系统 UserManager用来操作用户的类, Singi用来身份认证的 添加AccountController 先声明SignInManager和UserManager这两个服务 ...

  6. ccflow汇总帖

    视频教程学习 公司电脑路径; E:\开源工作流\ccflow佳怡物流版\ccflow\doc cclfow的码云地址: https://gitee.com/opencc/ccflow 在线demo演示 ...

  7. linux mplayer 播放yuv格式 (转载)

    转自:http://blog.csdn.net/ly0303521/article/details/38713791 在mplayer中查看YUV格式的图片或视频,可使用如下命令: mplayer - ...

  8. E20180410-hm

    preface  n. 序言,引语; 开端,前奏; [宗] (弥撒的) 序诵,序祷;        vi. 作序; 作为…的序言,作为…的开端; 给…作序; 开始,导致; continue vi. 持 ...

  9. 862. Shortest Subarray with Sum at Least K

    Return the length of the shortest, non-empty, contiguous subarray of A with sum at least K. If there ...

  10. poj1664【DFS】

    思路:搜一下,还想多了,记得以前做过把一个数搞成几个数的相加组合,然后这题无非就是多了个组合的个数<=m的,那么只要多加一个条件,当num>m的时候也return掉就好了. //#incl ...