彩色立方体、

【分析】

弄清楚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. Sublime Text:初学者不知道的那些事

    来源:Duchessjojo@译言 我是Sublime Text代码编辑器的忠实粉丝.我和诸多Mac程序员一样,最初使用的是Textmate代码编辑器.在Sublime Text 2发行后,我才开始转 ...

  2. unit_2_homework

    随记2018/4/23 # 找元祖中的元素,移除每个元素的空格,并查找以a或A开头,c结尾的所有元素. # 思路:将i取出来,求得li列表中有多少个元素for i in range(len(li)): ...

  3. 怎样取得selected的option选项的value值

    现在有一id=test的下拉框,怎么拿到选中的那个值呢?   分别使用javascript原生的方法和jquery方法   <select id="test"  name=& ...

  4. redis缓存分页思路

    传统分页一般分页做缓存都是直接查找出来,按页放到缓存里,但是这种缓存方式有很多缺点.如缓存不能及时更新,一旦数据有变化,所有的之前的分页缓存都失效了.比如像微博这样的场景,微博下面现在有一个顶次数的排 ...

  5. ConcurrentHashMap的实现原理与使用

    一.适应ConcurrentHashMap的原因 HashMap存在线程不安全的问题,HashTable效率十分低下,因此,ConcurrentHashMap有了合适的登场机会. (1)HashTab ...

  6. [JAVA] 小数转百分数

    import java.text.NumberFormat; //获取格式化对象 NumberFormat format = NumberFormat.getPercentInstance(); // ...

  7. Mysql中结果集(mysql_result)与Traversable

    对于MySQL应该也不是很陌生吧,我常常爱犯的以错误就是执行mysli_qurey()后就使用数据,忘记返回的是结果集了.而对于lSELECT,.SHOW, DESCRIBE . EXPLAINmys ...

  8. vi/vim 消除搜索后的关键字高亮

    使用vi或vim命令搜索某个关键字之后,取消高亮显示的方法 只要输入:noh即可

  9. MVC错误(一)

    目录规范后将相应的文件放到该放的地方后,应修改require_once();中的路径 调试php代码时先打开WampServer,再在浏览器中输入localhost/文件夹名/index.php

  10. python report中文显示乱码

    环境:python2.7 测试框架: nose (1.3.7) nose-html-reporting (0.2.3) 问题:生成测试报告失败的时候,报告会抓取代码中的print,打开后看到的中文是乱 ...