白书第一章例题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. python(一):multiprocessing——死锁

    前言近年来,使用python的人越来越多,这得益于其清晰的语法.低廉的入门代价等因素.尽管python受到的关注日益增多,但python并非完美,例如被人诟病最多的GIL(值得注意的是,GIL并非py ...

  2. 文件的创建,读取,写入,修改,删除---python入门

    转自:http://blog.163.com/jackylau_v/blog/static/175754040201181505158356/ 一.用Python创建一个新文件,内容是从0到9的整数, ...

  3. linux基于流的文件操作

    1 打开流的函数 FIEL * fopen(const char * restrict pathname,const char* restrict type) FILE *fdopen(int fil ...

  4. 洛谷 - P1002 - 过河卒 - 简单dp

    https://www.luogu.org/problemnew/show/P1002 方程很好想,题目也很暴力.感谢题目提示数据会很大. #include<bits/stdc++.h> ...

  5. Android Fragment使用小结及介绍

    目录(?)[-] 一什么是Fragment 二Fragment的生命周期 三Fragment的两种添加方式addreplace 四两种添加方式性能比较 偶记得第一次接触Fragment,觉得好牛叉的组 ...

  6. POJ2366【二分】

    题意: 给两个序列,问两个序列中是否有两个数加起来=1e4: 思路: 直接先排序好b序列,然后枚举a序列,二分查找b序列就好了: 贴一发挫code-. //#include <bits/stdc ...

  7. hdoj5667 BestCoder Round #80 【费马小定理(膜拜)+矩阵快速幂+快速幂】

    #include<cstdio> #include<string> #include<iostream> #include<vector> #inclu ...

  8. 超完整的Chrome浏览器客户端调试大全

    引言 “工欲善其事,必先利其器” 没错,这句话个人觉得说的特别有道理,举个例子来说吧,厉害的化妆师都有一套非常专业的刷子,散粉刷负责定妆,眼影刷负责打眼影,各司其职,有了专业的工具才能干专业的事,这个 ...

  9. Could not open logfile" occurred when run "datapatch -verbose"

    CAUSE Due to Bug 25459405 - DATAPATCH FAILS WITH SP2-0768 IF NLS_LANGUAGE IS NOT SET TO AMERICANwhic ...

  10. C#中的委托(转)

    C# 中的委托和事件 引言 委托 和 事件在 .Net Framework中的应用非常广泛,然而,较好地理解委托和事件对很多接触C#时间不长的人来说并不容易.它们就像是一道槛儿,过了这个槛的人,觉得真 ...