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 ...
随机推荐
- Centos7安装jekyll
1.首先需要安装相应的依赖包及所需要的工具 sudo yum install nodejs npm ruby ruby-devel rubygems git 2.修改gem源 国内 使用的淘宝的更新源 ...
- java 蓝桥杯基础练习 01字串 进制转换
问题描述 对于长度为5位的一个01串,每一位都可能是0或1,一共有32种可能.它们的前几个是: 请按从小到大的顺序输出这32种01串. 输入格式 本试题没有输入. 输出格式 输出32行,按从小到大的顺 ...
- java基础之HashSet如何保证对象的唯一性
首先Set集合是无序的 不可重复的 add的时候判断对象是否重复是用的equals HashSet<String> 存储String类型的数据时是可以保证数据的唯一性的 因为String类 ...
- 新做的系统,第一次拉maven项目时,鼠标左键+ctrl键不能进方法
对项目选择属性,跳转至:选择以下步骤
- 微信小程序(应用号)开发教程
本文档将带你一步步创建完成一个微信小程序,并可以在手机上体验该小程序的实际效果.这个小程序的首页将会显示欢迎语以及当前用户的微信头像,点击头像,可以在新开的页面中查看当前小程序的启动日志.下载源码 1 ...
- 269. Alien Dictionary火星语字典(拓扑排序)
[抄题]: There is a new alien language which uses the latin alphabet. However, the order among letters ...
- ServiceStack.redis用法
using System; using System.Collections.Generic; using ServiceStack.Redis; namespace SysBuild { class ...
- [ASP.NET MVC 小牛之路]03 - Razor语法(转)
出处:http://www.cnblogs.com/willick/p/3224144.html Razor是MVC3中才有的新的视图引擎.我们知道,在ASP.NET中,ASPX的视图引擎依靠< ...
- UDP问题
这两天使用C#的UdpClient,本机的服务是采用MFC的socket发的,用C#做客户端,然后客户端启动时,出现该条错误信息 ==通常每个套接字地址(协议/网络地址/端口)只允许使用一次. 笔记的 ...
- 【转载】rabbitmq的发布确认和事务
地址:https://my.oschina.net/lzhaoqiang/blog/670749 摘要: 介绍confirm的工作机制.使用spring-amqp介绍事务以及发布确认的使用方式.因为事 ...