题目

https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1402

题意

4个方块,每个方块每个面涂不同的颜色,问最少重涂多少面,使四个方块相同。

思路

如刘书思路,明显,方块是可以旋转的。旋转的方式不可能多。旋转的基本操作可以定为右旋和上旋,其他所有旋转都是这两种子操作的集合。

通过搜索确定所有可能的旋转方式后,接下来就是确定该如何涂色。

选定第一个方块作为参考系,对剩下的方块分别尝试一下可能的旋转方式。确定旋转方式后,答案就很简单的相加即得。

感想

1. 三倍ice cream!

代码

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <tuple>
#include <set>
#include <map>
#include <cassert>
#define LOCAL_DEBUG
using namespace std;
const int MAXN = ;
int rightPositions[] = { , , , , , };
int topPositions[] = { , , , , , };
int n; class Status {
public:
int faces[];
Status() {
for (int i = ; i < ; i++) {
faces[i] = i;
}
}
Status(int _faces[]) {
for (int i = ; i < ; i++) {
faces[i] = _faces[i];
}
} bool operator ==(const Status & other)const {
for (int i = ; i < ; i++) {
if (faces[i] != other.faces[i])return false;
}
return true;
} bool operator <(const Status & other)const {
for (int i = ; i < ; i++) {
if (faces[i] < other.faces[i])return true;
else if (faces[i] > other.faces[i])return false;
}
return false;
} void rotate(int positions[]) {
int tmp[];
for (int i = ; i < ; i++) {
tmp[i] = faces[i];
}
for (int i = ; i < ; i++) {
faces[i] = tmp[positions[i]];
}
} void reRotate(int positions[]) {
int tmp[];
for (int i = ; i < ; i++) {
tmp[i] = faces[i];
}
for (int i = ; i < ; i++) {
faces[positions[i]] = tmp[i];
}
} Status copy() {
Status newStatus;
for (int i = ; i < ; i++) {
newStatus.faces[i] = faces[i];
}
return newStatus;
}
}; set<Status> statuses; void buildStatus() {
queue<Status> que;
Status status;
que.push(status);
statuses.insert(status);
while (!que.empty()) {
status = que.front(); que.pop();
Status newStatus = status.copy();
newStatus.rotate(rightPositions);
if (statuses.count(newStatus) == ) {
que.push(newStatus);
statuses.insert(newStatus);
}
newStatus = status.copy();
newStatus.rotate(topPositions);
if (statuses.count(newStatus) == ) {
que.push(newStatus);
statuses.insert(newStatus);
}
}
} Status cubes[MAXN];
int cnt[MAXN * ]; int dfs(int id) {
int ans = * MAXN;
if (id < n) {
for (auto status : statuses) {
cubes[id].rotate(status.faces);
ans = min(dfs(id + ), ans);
cubes[id].reRotate(status.faces);
}
}
else {
ans = ;
for (int j = ; j < ; j++) {
for (int i = ; i < n; i++) {
cnt[cubes[i].faces[j]] ++;
}
int best_color = ;
for (int i = ; i < MAXN * ; i++) {
if (cnt[i] > cnt[best_color]) {
best_color = i;
}
}
ans += n - cnt[best_color];
memset(cnt, , sizeof(cnt));
}
}
return ans;
} int main() {
#ifdef LOCAL_DEBUG
freopen("input.txt", "r", stdin);
//freopen("output2.txt", "w", stdout);
#endif // LOCAL_DEBUG
buildStatus();
for (int ti = ; scanf("%d", &n) == && n; ti++) {
map<string, int> colorNameMap;
for (int i = ; i < n; i++) {
for (int j = ; j < ; j++) {
char tmp[];
scanf("%s", tmp);
string colorName = tmp;
if (colorNameMap.count(colorName) == ) {
colorNameMap[colorName] = colorNameMap.size();
}
cubes[i].faces[j] = colorNameMap[colorName];
}
}
int ans = dfs();
printf("%d\n", ans);
} return ;
}

UVALive 3401 - Colored Cubes 旋转 难度: 1的更多相关文章

  1. UVALive - 3401 Colored Cubes

    好久没写解题回顾了.主要是没什么时间,但是还是一直在刷题,图论刷了70%的知识点,不过感觉长进不是很大,所以觉得还是得一步步来,最近还是先从刘汝佳大白书把前面基础章节刷完然后再决定以后的训练方式吧. ...

  2. UVaLive 3401 Colored Cubes (暴力)

    题意:给定n个立方体,让你重新涂尽量少的面,使得所有立方体都相同. 析:暴力求出每一种姿态,然后枚举每一种立方体的姿态,求出最少值. 代码如下: #pragma comment(linker, &qu ...

  3. LA 3401 - Colored Cubes

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

  4. 1352 - Colored Cubes (枚举方法)

    There are several colored cubes. All of them are of the same size but they may be colored differentl ...

  5. UVA 10733 - The Colored Cubes(Ploya)

    UVA 10733 - The Colored Cubes 题目链接 题意:一个立方体.n种颜色,问能涂成多少不同立方体 思路:Ploya求解,正方体相应24种不同旋转一一计算出循环个数就可以.和 U ...

  6. POJ2741 Colored Cubes

    Description There are several colored cubes. All of them are of the same size but they may be colore ...

  7. UVALive 3401 彩色立方体

    https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...

  8. 【poj2741】 Colored Cubes

    http://poj.org/problem?id=2741 (题目链接) 题意 给出n个骰子,每一面都有一种颜色,问最少更改多少个面的颜色可以使所有骰子通过旋转后完全相同. solution 迷之d ...

  9. uva 10733 The Colored Cubes<polya定理>

    链接:http://uva.onlinejudge.org/external/107/10733.pdf 题意: N 种颜色可以涂成多少种立方体~ 思路: 使正六面体保持不变的运动群总共有: 1.不变 ...

随机推荐

  1. feature map 大小以及反卷积的理解

    (1)边长的计算公式是:  output_h =(originalSize_h+padding*2-kernelSize_h)/stride +1 输入图片大小为200×200,依次经过一层卷积(ke ...

  2. Codeforces 833 C - Ever-Hungry Krakozyabra

    思路: 首先,inedible tails 的个数最多为C(18+9,9)个(用隔板法),所以我们暴力出所有的 inedible tails,然后检查一下在[L, R]这段区间是否存在这个inedib ...

  3. 第 2 章 容器架构 - 007 - Docker 架构详解

    Docker 的核心组件包括: Docker 客户端 - Client Docker 服务器 - Docker daemon Docker 镜像 - Image Registry Docker 容器 ...

  4. Mysql数据库如何自动备份

    Mysql数据库如何自动备份 一.总结 一句话总结:用navicat配合windows的批处理即可 navicat windows批处理 二.Mysql数据库自动备份 参考:Mysql数据库自动备份 ...

  5. 雷林鹏分享:jQuery EasyUI 窗口 - 自定义带有工具条和按钮的对话框

    jQuery EasyUI 窗口 - 自定义带有工具条和按钮的对话框 您可以创建一个带有工具栏(toolbar)和按钮(button)的对话框(dialog),可以从 HTML 标记创建.这个教程描述 ...

  6. BIO NIO AIO之间的区别

    一.BIO.NIO.AIO的基本定义与类比描述: BIO (Blocking I/O):同步阻塞I/O模式,数据的读取写入必须阻塞在一个线程内等待其完成.这里使用那个经典的烧开水例子,这里假设一个烧开 ...

  7. JavaScript动态加载资源

    //动态加载样式 function dynamicLoadingCss(path){ if(!path || path.length === 0){ return false; } var head ...

  8. php的抓取

    <?php/** * Created by PhpStorm. * User: s * Date: 2018/11/6 * Time: 18:14 */ include "vendor ...

  9. C# 有哪些集合

    队列[Queue] //队列:先进先出 /* *增加元素到队列结尾处 *移除队列开始处 */ Queue queue=new Queue(); queue.Enqueue(Object); queue ...

  10. PAT 1027 Colors in Mars

    1027 Colors in Mars (20 分)   People in Mars represent the colors in their computers in a similar way ...