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.不变 ...
随机推荐
- linux/unix下 pid文件作用浅析
l在linux系统的目录/var/run下面一般我们都会看到很多的*.pid文件.而且往往新安装的程序在运行后也会在/var/run目录下面产生自己的pid文件.那么这些pid文件有什么作用呢?它的内 ...
- c++实现数值的整数次方(类似pow())作用
/* * 计算数值的整数次方.cpp * * Created on: 2018年4月13日 * Author: soyo */ #include<iostream> #include< ...
- Entity Framework 实体间的外键关系
EF 默认是开户级联删除的,这此规则将会删除非空外键和多对多的关系,如果 在数据库上下文中的实体模型类 存在着 级联引用和多重删除路径,那么EF就抛出 级联引用和多重删除路径的异常. Introduc ...
- ASP.NET Core MVC 2.x 全面教程_ASP.NET Core MVC 08. 输入Model和防止重复Post
通过action的参数传入一个model 通过input的name属性和model属性对应上 通常是使用Http post去做 快速创建了这个Action 这个Action很简单我们只需要返回View ...
- 任务34:Cookie-based认证实现
任务34:Cookie-based认证实现 用mvc来实现以下Cookie-Base的认证和授权的方式 新建一个web MVC的项目 在我的电脑的路径:D:\MyDemos\jesse Ctrl+鼠标 ...
- 斯坦福CS231n—深度学习与计算机视觉----学习笔记 课时6
课时6 线性分类器损失函数与最优化(上) 多类SVM损失:这是一个两分类支持向量机的泛化 SVM损失计算了所有不正确的例子,将所有不正确的类别的评分,与正确类别的评分之差加1,将得到的数值与0作比较, ...
- 洛谷 - P1141 - 01迷宫 - dfs
https://www.luogu.org/problemnew/show/P1141 能互相到达的格子的答案自然是一样的,第一次dfs标记联通块,第二次dfs把cnt传递到整个联通卡并顺手消除vis ...
- 786. K-th Smallest Prime Fraction
A sorted list A contains 1, plus some number of primes. Then, for every p < q in the list, we co ...
- mac 配置nginx 虚拟域名(转载)
我是通过homebrew 安装nginx 的,所以安装目录是默认的,之前多个server都是放在默认安装目录下的nginx.conf里的,但是这样不太好,就是会导致nginx.conf 越来越长,而且 ...
- HBuilder mui 报错No 'Access-Control-Allow-Origin' header
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' he ...