UVaLive 3401 Colored Cubes (暴力)
题意:给定n个立方体,让你重新涂尽量少的面,使得所有立方体都相同。
析:暴力求出每一种姿态,然后枚举每一种立方体的姿态,求出最少值。
代码如下:
- #pragma comment(linker, "/STACK:1024000000,1024000000")
- #include <cstdio>
- #include <string>
- #include <cstdlib>
- #include <cmath>
- #include <iostream>
- #include <cstring>
- #include <set>
- #include <queue>
- #include <algorithm>
- #include <vector>
- #include <map>
- #include <cctype>
- #include <cmath>
- #include <stack>
- #define debug() puts("++++");
- #define gcd(a, b) __gcd(a, b)
- #define lson l,m,rt<<1
- #define rson m+1,r,rt<<1|1
- #define freopenr freopen("in.txt", "r", stdin)
- #define freopenw freopen("out.txt", "w", stdout)
- using namespace std;
- typedef long long LL;
- typedef unsigned long long ULL;
- typedef pair<int, int> P;
- const int INF = 0x3f3f3f3f;
- const double inf = 0x3f3f3f3f3f3f;
- const double PI = acos(-1.0);
- const double eps = 1e-5;
- const int maxn = 20000 + 10;
- const int mod = 1e6 + 10;
- const int dr[] = {-1, 0, 1, 0};
- const int dc[] = {0, 1, 0, -1};
- const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
- int n, m;
- const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
- const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
- inline bool is_in(int r, int c){
- return r >= 0 && r < n && c >= 0 && c < m;
- }
- const int dice24[24][6] = {
- {2, 1, 5, 0, 4, 3},
- {2, 0, 1, 4, 5, 3},
- {2, 4, 0, 5, 1, 3},
- {2, 5, 4, 1, 0, 3},
- {4, 2, 5, 0, 3, 1},
- {5, 2, 1, 4, 3, 0},
- {1, 2, 0, 5, 3, 4},
- {0, 2, 4, 1, 3, 5},
- {0, 1, 2, 3, 4, 5},
- {4, 0, 2, 3, 5, 1},
- {5, 4, 2, 3, 1, 0},
- {1, 5, 2, 3, 0, 4},
- {5, 1, 3, 2, 4, 0},
- {1, 0, 3, 2, 5, 4},
- {0, 4, 3, 2, 1, 5},
- {4, 5, 3, 2, 0, 1},
- {1, 3, 5, 0, 2, 4},
- {0, 3, 1, 4, 2, 5},
- {4, 3, 0, 5, 2, 1},
- {5, 3, 4, 1, 2, 0},
- {3, 4, 5, 0, 1, 2},
- {3, 5, 1, 4, 0, 2},
- {3, 1, 0, 5, 4, 2},
- {3, 0, 4, 1, 5, 2},
- };
- map<string, int> mp;
- int dice[10][10];
- int ans;
- int r[10];
- int getId(const string &s){
- if(mp.count(s)) return mp[s];
- return mp[s] = mp.size();
- }
- int color[10][10];
- void judge(){
- for(int i = 0; i < n; ++i)
- for(int j = 0; j < 6; ++j) color[i][dice24[r[i]][j]] = dice[i][j];
- int tot = 0;
- for(int i = 0; i < 6; ++i){
- int cnt[30];
- memset(cnt, 0, sizeof cnt);
- int mmax = 0;
- for(int j = 0; j < n; ++j) mmax = max(mmax, ++cnt[color[j][i]]);
- tot += n - mmax;
- }
- ans = min(ans, tot);
- }
- void dfs(int d){
- if(d == n){ judge(); return ; }
- for(int i = 0; i < 24; ++i){
- r[d] = i;
- dfs(d+1);
- }
- }
- int main(){
- while(cin >> n && n){
- mp.clear();
- string s;
- for(int i = 0; i < n; ++i)
- for(int j = 0; j < 6; ++j){
- cin >> s;
- dice[i][j] = getId(s);
- }
- ans = n * 6;
- r[0] = 0;
- dfs(1);
- cout << ans << endl;
- }
- return 0;
- }
UVaLive 3401 Colored Cubes (暴力)的更多相关文章
- UVALive 3401 - Colored Cubes 旋转 难度: 1
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...
- UVALive - 3401 Colored Cubes
好久没写解题回顾了.主要是没什么时间,但是还是一直在刷题,图论刷了70%的知识点,不过感觉长进不是很大,所以觉得还是得一步步来,最近还是先从刘汝佳大白书把前面基础章节刷完然后再决定以后的训练方式吧. ...
- LA 3401 - Colored Cubes
解题报告:有n(1<=n<=4)个立方体,每个立方体的每一个面涂有一种颜色,现在要将这些立方体的某些面的颜色重新涂一下,使得这n个立方体旋转到某一种状态下,对应的面的颜色都相同. 这题可以 ...
- 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 ...
- Gym 100299C && UVaLive 6582 Magical GCD (暴力+数论)
题意:给出一个长度在 100 000 以内的正整数序列,大小不超过 10^ 12.求一个连续子序列,使得在所有的连续子序列中, 它们的GCD值乘以它们的长度最大. 析:暴力枚举右端点,然后在枚举左端点 ...
- poj1543-Perfect Cubes(暴力)
水题:求n^3 = a^3 + b^3 + c^3 ;暴力即可 #include<iostream> using namespace std; int main(){ int n ; c ...
- 【poj2741】 Colored Cubes
http://poj.org/problem?id=2741 (题目链接) 题意 给出n个骰子,每一面都有一种颜色,问最少更改多少个面的颜色可以使所有骰子通过旋转后完全相同. solution 迷之d ...
随机推荐
- Go -- 实现二叉搜索树
树: https://suanfa.herokuapp.com/3%E6%A0%91/binarytree/ 数据结构 首先我们定义需要的数据结构.注意,TreeNode的左右节点都是*TreeNod ...
- BUPT 2012复试机考 4T
题目描述 我们都学习过计算机网络,知道网络层IP协议数据包的头部格式如下: 其中IHL表示IP头的长度,单位是4字节:总长表示整个数据包的长度,单位是1字节.传输层的TCP协议数据段的头部格式如下: ...
- php 中函数获取可变参数的方法, 这个语法有点像 golang 语言中的
原文呢:http://php.net/manual/en/functions.arguments.php#functions.arguments.type-declaration.strict Onl ...
- MBProgressHUD 显示方向异常
一直在iphone上使用MBProgressHUD做提示信息视图.一直都没有什么问题,但用在ipad上使用时.却有时会出现显示方向不正常.如ipad屏幕是横的,但当MBProgressHUD出现时却依 ...
- 删除DataGridView选中行并更新数据库
前面写过一篇文章是DataGridView控件显示数据的,DataGridView在与数据库打交道时会常常出现,也非常有用.通过DataGridView对数据库进行更改和查询都比較方便. 这里我们须要 ...
- SpringBoot学习之快速入门创建
maven构建项目 1.访问http://start.spring.io/,进入快速创建工程的主页 可参考下图所示: 2.选择构建工具Maven Project.Spring Boot版本1.3.6以 ...
- RecyclerView(替代ListView)使用方法介绍
在build.gradle文件加入以下代码 compile 'com.android.support:cardview-v7:21.0.3' compile 'com.android.support: ...
- 用NHibernate处理带属性的多对多关系
1.引言 老谭在面试开发者的时候,为了考察他们的数据库开发能力,经常祭出我的法宝,就是大学数据库教程中讲到的一个模式:学生选课.这个模式是这种: 在这个模式中,学生(Student)和课程(Cours ...
- python day- 6 is 和 ==的区别 encode 和 decode
1.is 和 == 的区别. == 是由来判断左右两边的内容是否相等. is 是用来判断内存地址是否相同. 引进 id ( )函数 小数据池: 对于字符串 ,数字 ,bool 值进行 id()计 ...
- cocos2d-x交叉编译到安卓
ccocos2d-x是一个基于MIT协议的开源框架,用于构建游戏.应用程序和其它图形界面交互应用. 它的最大特点就是跨平台性,支持IOS, Android.Windows, WindowsPhone等 ...