LA 3401
彩色立方体、
【分析】

弄清楚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的更多相关文章
- LA 3401 - Colored Cubes
解题报告:有n(1<=n<=4)个立方体,每个立方体的每一个面涂有一种颜色,现在要将这些立方体的某些面的颜色重新涂一下,使得这n个立方体旋转到某一种状态下,对应的面的颜色都相同. 这题可以 ...
- 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 ...
- 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 ...
- hdu 3401 单调队列优化DP
Trade Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status ...
- Mac Pro 使用 ll、la、l等ls的别名命令
在 Linux 下习惯使用 ll.la.l 等ls别名的童鞋到 mac os 可就郁闷了~~ 其实只要在用户目录下建立一个脚本“.bash_profile”, vim .bash_profile 并输 ...
- Linux中的动态库和静态库(.a/.la/.so/.o)
Linux中的动态库和静态库(.a/.la/.so/.o) Linux中的动态库和静态库(.a/.la/.so/.o) C/C++程序编译的过程 .o文件(目标文件) 创建atoi.o 使用atoi. ...
- 【HDU 3401 Trade】 单调队列优化dp
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3401 题目大意:现在要你去炒股,给你每天的开盘价值,每股买入价值为ap,卖出价值为bp,每天最多买as ...
- Mac OS使用ll、la、l等ls的别名命令
在linux下习惯使用ll.la.l等ls别名的童鞋到mac os可就郁闷了-- 其实只要在用户目录下建立一个脚本“.bash_profile”,并输入以下内容即可: alias ll='ls -al ...
- HDU 3401 Trade dp+单调队列优化
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3401 Trade Time Limit: 2000/1000 MS (Java/Others)Mem ...
随机推荐
- 转载--浅谈spring4泛型依赖注入
转载自某SDN-4O4NotFound Spring 4.0版本中更新了很多新功能,其中比较重要的一个就是对带泛型的Bean进行依赖注入的支持.Spring4的这个改动使得代码可以利用泛型进行进一步的 ...
- 129. Sum Root to Leaf Numbers(Tree; DFS)
Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number ...
- 通过Scanner从控制台获取数据
----------siwuxie095 Scanner类用于扫描从控制台输入的数据,可以接收字符串和基本数据类型的数据 Scanner类位于 java.util.Scanner 包中 Scanner ...
- zabbix结合grafana
一.下载grafana 下载地址: http://docs.grafana.org/installation/rpm/ https://s3-us-west-2.amazonaws.com/grafa ...
- spring+springmvc+mybatis+redis实现缓存
先搭建好redis环境 需要的jar如下: jdbc.driverClassName=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://localhost:330 ...
- catkin_make与gtest出现冲突的问题与解决
gtest是测试时调用的,把测试禁止掉试试 catkin_make --pkg pkgname -DCATKIN_ENABLE_TESTING=0
- 解决VirtualBox 上的XP 关机时重启 , 启动时蓝屏 ,点击电源选项蓝屏
三个问题一次性解决. 启动时的蓝屏显示错误信息是: STOP 0x000000CE (...) DRIVER_UNLOADED_WITHOUT_CANCELLING_PENDING_OPERATION ...
- tp5写日志
- linux ubuntu 各目录大小
/home 45k /bin 8.7M /lib 370M /mnt 4.1k /run 36k /sbin 11M /tmp 41k /usr/share 770M
- 兼容低于IE9不支持html5标签的元素的方法
方法一: <!--[if lt IE9]> <script> (function() { if (! /*@cc_on!@*/ 0) retur ...