uva1352 Colored Cubes LA3401
白书第一章例题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的更多相关文章
- 1352 - Colored Cubes (枚举方法)
There are several colored cubes. All of them are of the same size but they may be colored differentl ...
- UVA 10733 - The Colored Cubes(Ploya)
UVA 10733 - The Colored Cubes 题目链接 题意:一个立方体.n种颜色,问能涂成多少不同立方体 思路:Ploya求解,正方体相应24种不同旋转一一计算出循环个数就可以.和 U ...
- POJ2741 Colored Cubes
Description There are several colored cubes. All of them are of the same size but they may be colore ...
- UVALive 3401 - Colored Cubes 旋转 难度: 1
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...
- 【poj2741】 Colored Cubes
http://poj.org/problem?id=2741 (题目链接) 题意 给出n个骰子,每一面都有一种颜色,问最少更改多少个面的颜色可以使所有骰子通过旋转后完全相同. solution 迷之d ...
- LA 3401 - Colored Cubes
解题报告:有n(1<=n<=4)个立方体,每个立方体的每一个面涂有一种颜色,现在要将这些立方体的某些面的颜色重新涂一下,使得这n个立方体旋转到某一种状态下,对应的面的颜色都相同. 这题可以 ...
- UVALive - 3401 Colored Cubes
好久没写解题回顾了.主要是没什么时间,但是还是一直在刷题,图论刷了70%的知识点,不过感觉长进不是很大,所以觉得还是得一步步来,最近还是先从刘汝佳大白书把前面基础章节刷完然后再决定以后的训练方式吧. ...
- 【codeforces 1025E】Colored Cubes 【构造】
题意 有一个n*n的棋盘和m个棋子,每个棋子有一个初始位置和一个目标位置,每次移动只能选择一个棋子移动到他相邻的格子,并且花费一秒钟.请你找出一个移动的方法,使得在10800步内将所有棋子移动到目标位 ...
- uva 10733 The Colored Cubes<polya定理>
链接:http://uva.onlinejudge.org/external/107/10733.pdf 题意: N 种颜色可以涂成多少种立方体~ 思路: 使正六面体保持不变的运动群总共有: 1.不变 ...
随机推荐
- 安装ubuntu gnome 16.04后的一些操作
好吧...其实安装了挺久了,记录一下以防忘记... 1.软件 chrome浏览器 唔..自己去官网下吧.. gnome tweak tool 不用多说,必备 sudo apt-get install ...
- js dom element 属性整理(原创)
最近去几家公司面试,发现大多数时候面试的内容考的都是原生的js语法和属性,所以我决心整理一下原生的dom元素的属性. 首先,我我们需要获取一个element元素 <li id="2&q ...
- atof和atoi
atof:将字串转换成浮点型数 表头文件 #include <stdlib.h> 函数说明 atof()会扫描参数nptr字符串,跳过前面的空格字符,直到遇上数字或正负符号才开始做转换,而 ...
- 黑马传智JavaEE57期 2019最新基础+就业+在职加薪_汇总
黑马传智JavaEE57期 2019最新基础+就业+在职加薪 阶段1 语言基础+高级· 1-1-Java基础语法 第14节 数组 111
- Goroutine被动调度之一(18)
本文是<Go语言调度器源代码情景分析>系列的第18篇,也是第四章<Goroutine被动调度>的第1小节. 前一章我们详细分析了调度器的调度策略,即调度器如何选取下一个进入运行 ...
- Cloudera Manager是啥?主要是干啥的?
简单来说,Cloudera Manager是一个拥有集群自动化安装.中心化管理.集群监控.报警功能的一个工具(软件),使得安装集群从几天的时间缩短在几个小时内,运维人员从数十人降低到几人以内,极大的提 ...
- bzoj 5019 [Snoi2017]遗失的答案
题面 https://www.lydsy.com/JudgeOnline/problem.php?id=5019 题解 如果L不是G的倍数 答案为0 下面考虑G|L的情况 将G,L质因数分解 设$L= ...
- codeforces 629C Famil Door and Brackets (dp + 枚举)
题目链接: codeforces 629C Famil Door and Brackets 题目描述: 给出完整的括号序列长度n,现在给出一个序列s长度为m.枚举串p,q,使得p+s+q是合法的括号串 ...
- LightOj 1076 - Get the Containers (折半枚举好题)
题目链接: http://www.lightoj.com/volume_showproblem.php?problem=1076 题目描述: 给出n个数,要求分成m段,问这m段中最大的总和,最小是多少 ...
- 洛谷 P2398 GCD SUM || uva11417,uva11426,uva11424,洛谷P1390,洛谷P2257,洛谷P2568
https://www.luogu.org/problemnew/show/P2398 $原式=\sum_{k=1}^n(k\sum_{i=1}^n\sum_{j=1}^n[(i,j)=k])$ 方法 ...