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.不变 ...
随机推荐
- [laravel]要点
1. routing 2. Ioc 3. Facade 4. Artisan 1.routing 参考:http://laravel.com/docs/4.2/routing 了解routing之前先 ...
- MyBatis相关资源
MyBatis很多项目中有用到,但会用并不表示你真正理解它,更不代表你能很清楚的教会别人.如果想在会用它的基础上更深入的通过学习它而提升自己技术能力,可利用下面资源. 1.官网文档,基本概念讲的很清楚 ...
- View Controller Programming Guide for iOS---(八)---Using View Controllers in the Responder Chain
Using View Controllers in the Responder Chain 响应链中使用视图控制器 View controllers are descendants of the UI ...
- vue的方法和计算属性的区别
首先看看 methods 方法 // html <div id="vue"> <button v-on:click = "a++">ad ...
- adb shell报错:error: insufficient permissions for device的解决办法
1.错误描述 执行 adb shell 时,报错如下; error: insufficient permissions for device 2.解决办法 1,终端执行 lsusb 结果如下,注意绿 ...
- iOS开发隐藏tabBar的问题
开发中遇到第一个页面需要显示tabBar,但是第二个页面不需要显示,当回到第一个页面的时候又需要显示的情况. 在第一个页面跳转到第二个页面的时候需要给第二个页面设置tabBar的隐藏 - (void) ...
- 文件共享服务 FTP,NFS 和 Samba
DAS DAS 指 Direct Attached Storage,即直连附加存储,这种设备直接连接到计算机主板总线上,计算机将其识别为一个块设备,例如常见的硬盘,U 盘等,这种设备很难做到共享. N ...
- java中stringBuilder的用法
java中stringBuilder的用法 String对象是不可改变的.每次使用 System.String类中的方法之一时,都要在内存中创建一个新的字符串对象,这就需要为该新对象分配新的空间.在需 ...
- Setting up IPS/inline for Linux in Suricata
不多说,直接上干货! 见官网 https://suricata.readthedocs.io/en/latest/setting-up-ipsinline-for-linux.html Docs » ...
- [转]Android APK签名原理及方法
准备知识:数据摘要 这个知识点很好理解,百度百科即可,其实他也是一种算法,就是对一个数据源进行一个算法之后得到一个摘要,也叫作数据指纹,不同的数据源,数据指纹肯定不一样,就和人一样. 消息摘要算法(M ...