彩色立方体、

【分析】

弄清楚24种状态,可以由标准姿态旋转而来。

计算24种状态:

#include <iostream>
#include <string> int left[] = { ,,,,, };
int up[] = { ,,,,, }; //按照排列T旋转姿态p
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_permutations()
{
int p0[] = { ,,,,, };
printf("int dice24[24][6] = {\n");
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++)
{
printf("{%d,%d,%d,%d,%d,%d},\n", p[], p[], p[], p[], p[], p[]);
rot(left, p);
}
}
printf("};\n");
} int main()
{
enumerate_permutations();
return ;
}

得到结果

直接用到最终程序中

//2019.4.23 彩色立方体
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std; const int maxn = ;
int n, dice[maxn][], ans;
int dice24[][] = {
{ ,,,,, },
{ ,,,,, },
{ ,,,,, },
{ ,,,,, },
{ ,,,,, },
{ ,,,,, },
{ ,,,,, },
{ ,,,,, },
{ ,,,,, },
{ ,,,,, },
{ ,,,,, },
{ ,,,,, },
{ ,,,,, },
{ ,,,,, },
{ ,,,,, },
{ ,,,,, },
{ ,,,,, },
{ ,,,,, },
{ ,,,,, },
{ ,,,,, },
{ ,,,,, },
{ ,,,,, },
{ ,,,,, },
{ ,,,,, },
}; vector<string> names;
int ID(const char* name)
{
string s(name);
int n = names.size();
for (int i = ; i < n; i++)
if (names[i] == s) return i;
names.push_back(s);
return n;
} int r[maxn], color[maxn][]; void check()
{
for (int i = ; i < n; i++)
for (int j = ; j < ; j++)
color[i][dice24[r[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()
{
while (scanf_s("%d", &n) == && n)
{
names.clear();
for(int i=;i<n;i++)
for (int j = ; j < ; j++)
{
char name[];
scanf_s("%s", name);
dice[i][j] = ID(name);
}
ans = n * ;
r[] = ;
dfs();
printf("%d\n", ans);
}
return ;
}

LA 3401的更多相关文章

  1. LA 3401 - Colored Cubes

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

  2. leggere la nostra recensione del primo e del secondo

    La terra di mezzo in trail running sembra essere distorto leggermente massima di recente, e gli aggi ...

  3. Le lié à la légèreté semblait être et donc plus simple

    Il est toutefois vraiment à partir www.runmasterfr.com/free-40-flyknit-2015-hommes-c-1_58_59.html de ...

  4. hdu 3401 单调队列优化DP

    Trade Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status ...

  5. Mac Pro 使用 ll、la、l等ls的别名命令

    在 Linux 下习惯使用 ll.la.l 等ls别名的童鞋到 mac os 可就郁闷了~~ 其实只要在用户目录下建立一个脚本“.bash_profile”, vim .bash_profile 并输 ...

  6. Linux中的动态库和静态库(.a/.la/.so/.o)

    Linux中的动态库和静态库(.a/.la/.so/.o) Linux中的动态库和静态库(.a/.la/.so/.o) C/C++程序编译的过程 .o文件(目标文件) 创建atoi.o 使用atoi. ...

  7. 【HDU 3401 Trade】 单调队列优化dp

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3401 题目大意:现在要你去炒股,给你每天的开盘价值,每股买入价值为ap,卖出价值为bp,每天最多买as ...

  8. Mac OS使用ll、la、l等ls的别名命令

    在linux下习惯使用ll.la.l等ls别名的童鞋到mac os可就郁闷了-- 其实只要在用户目录下建立一个脚本“.bash_profile”,并输入以下内容即可: alias ll='ls -al ...

  9. HDU 3401 Trade dp+单调队列优化

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3401 Trade Time Limit: 2000/1000 MS (Java/Others)Mem ...

随机推荐

  1. Sass 入门 (一) 安装Sass

    Sass安装 ruby安装 因为sass依赖于ruby环境,所以装sass之前先确认装了ruby.先导官网下载个ruby 在安装的时候,请勾选Add Ruby executables to your ...

  2. kubenetes dns

    E0228 07:32:28.912833       1 reflector.go:201] k8s.io/dns/pkg/dns/dns.go:147: Failed to list *v1.En ...

  3. Unity Remote 5 使用

    从哪里下载,我是从应用商店里下载的 一. Android版 首先应该确保安装了最新的 Android SDK(这对于在设备上设置端口转发非常必要). 然后,使用 USB 连接线连接设备与电脑,并启动U ...

  4. 671. Second Minimum Node In a Binary Tree 非递减二叉树中第二小的元素

    [抄题]: Given a non-empty special binary tree consisting of nodes with the non-negative value, where e ...

  5. Selenium自动化测试WebDriver下载

    1. 所有版本chrome下载 是不是很难找到老版本的chrome?博主收集了几个下载chrome老版本的网站,其中哪个下载的是原版的就不得而知了. http://www.slimjet.com/ch ...

  6. [C++] any number to binary (Bit manipulation)

    any number to binary  (Bit manipulation)

  7. htaccess跨域

    目的:为了加快访问速度,减轻主站压力,把静态资源放到独立的服务器上,使用独立的域名 问题:浏览器为安全考虑,实施同源策略:ip/域名和端口必须相同 解决办法: 1.httpd.conf中,开启apac ...

  8. 修改字段注释modify

    alter table test1 modify 字段名 类型 comment '修改后的字段注释'; ALTER TABLE tc_activity_miaosha MODIFY `validity ...

  9. png 深度图像 转为 点云(opencv2)

    https://github.com/kruglov-dmitry/pnd2pcd_batch

  10. Part2_lesson2---ARM处理器工作模式

    arm公司发布的学习手册:ARM Architecture Reference Manual. 打开之: 找到Programmers' Model->A2.2 Processor modes. ...