题意:给定n个立方体,让你重新涂尽量少的面,使得所有立方体都相同。

析:暴力求出每一种姿态,然后枚举每一种立方体的姿态,求出最少值。

代码如下:

  1. #pragma comment(linker, "/STACK:1024000000,1024000000")
  2. #include <cstdio>
  3. #include <string>
  4. #include <cstdlib>
  5. #include <cmath>
  6. #include <iostream>
  7. #include <cstring>
  8. #include <set>
  9. #include <queue>
  10. #include <algorithm>
  11. #include <vector>
  12. #include <map>
  13. #include <cctype>
  14. #include <cmath>
  15. #include <stack>
  16. #define debug() puts("++++");
  17. #define gcd(a, b) __gcd(a, b)
  18. #define lson l,m,rt<<1
  19. #define rson m+1,r,rt<<1|1
  20. #define freopenr freopen("in.txt", "r", stdin)
  21. #define freopenw freopen("out.txt", "w", stdout)
  22. using namespace std;
  23.  
  24. typedef long long LL;
  25. typedef unsigned long long ULL;
  26. typedef pair<int, int> P;
  27. const int INF = 0x3f3f3f3f;
  28. const double inf = 0x3f3f3f3f3f3f;
  29. const double PI = acos(-1.0);
  30. const double eps = 1e-5;
  31. const int maxn = 20000 + 10;
  32. const int mod = 1e6 + 10;
  33. const int dr[] = {-1, 0, 1, 0};
  34. const int dc[] = {0, 1, 0, -1};
  35. const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
  36. int n, m;
  37. const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  38. const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  39. inline bool is_in(int r, int c){
  40. return r >= 0 && r < n && c >= 0 && c < m;
  41. }
  42. const int dice24[24][6] = {
  43. {2, 1, 5, 0, 4, 3},
  44. {2, 0, 1, 4, 5, 3},
  45. {2, 4, 0, 5, 1, 3},
  46. {2, 5, 4, 1, 0, 3},
  47. {4, 2, 5, 0, 3, 1},
  48. {5, 2, 1, 4, 3, 0},
  49. {1, 2, 0, 5, 3, 4},
  50. {0, 2, 4, 1, 3, 5},
  51. {0, 1, 2, 3, 4, 5},
  52. {4, 0, 2, 3, 5, 1},
  53. {5, 4, 2, 3, 1, 0},
  54. {1, 5, 2, 3, 0, 4},
  55. {5, 1, 3, 2, 4, 0},
  56. {1, 0, 3, 2, 5, 4},
  57. {0, 4, 3, 2, 1, 5},
  58. {4, 5, 3, 2, 0, 1},
  59. {1, 3, 5, 0, 2, 4},
  60. {0, 3, 1, 4, 2, 5},
  61. {4, 3, 0, 5, 2, 1},
  62. {5, 3, 4, 1, 2, 0},
  63. {3, 4, 5, 0, 1, 2},
  64. {3, 5, 1, 4, 0, 2},
  65. {3, 1, 0, 5, 4, 2},
  66. {3, 0, 4, 1, 5, 2},
  67. };
  68.  
  69. map<string, int> mp;
  70. int dice[10][10];
  71. int ans;
  72. int r[10];
  73.  
  74. int getId(const string &s){
  75. if(mp.count(s)) return mp[s];
  76. return mp[s] = mp.size();
  77. }
  78. int color[10][10];
  79.  
  80. void judge(){
  81. for(int i = 0; i < n; ++i)
  82. for(int j = 0; j < 6; ++j) color[i][dice24[r[i]][j]] = dice[i][j];
  83. int tot = 0;
  84. for(int i = 0; i < 6; ++i){
  85. int cnt[30];
  86. memset(cnt, 0, sizeof cnt);
  87. int mmax = 0;
  88. for(int j = 0; j < n; ++j) mmax = max(mmax, ++cnt[color[j][i]]);
  89. tot += n - mmax;
  90. }
  91. ans = min(ans, tot);
  92. }
  93.  
  94. void dfs(int d){
  95. if(d == n){ judge(); return ; }
  96. for(int i = 0; i < 24; ++i){
  97. r[d] = i;
  98. dfs(d+1);
  99. }
  100. }
  101.  
  102. int main(){
  103. while(cin >> n && n){
  104. mp.clear();
  105. string s;
  106. for(int i = 0; i < n; ++i)
  107. for(int j = 0; j < 6; ++j){
  108. cin >> s;
  109. dice[i][j] = getId(s);
  110. }
  111. ans = n * 6;
  112. r[0] = 0;
  113. dfs(1);
  114. cout << ans << endl;
  115. }
  116. return 0;
  117. }

UVaLive 3401 Colored Cubes (暴力)的更多相关文章

  1. UVALive 3401 - Colored Cubes 旋转 难度: 1

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

  2. UVALive - 3401 Colored Cubes

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

  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. Gym 100299C && UVaLive 6582 Magical GCD (暴力+数论)

    题意:给出一个长度在 100 000 以内的正整数序列,大小不超过 10^ 12.求一个连续子序列,使得在所有的连续子序列中, 它们的GCD值乘以它们的长度最大. 析:暴力枚举右端点,然后在枚举左端点 ...

  8. poj1543-Perfect Cubes(暴力)

    水题:求n^3 =  a^3 + b^3 + c^3 ;暴力即可 #include<iostream> using namespace std; int main(){ int n ; c ...

  9. 【poj2741】 Colored Cubes

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

随机推荐

  1. Go -- 实现二叉搜索树

    树: https://suanfa.herokuapp.com/3%E6%A0%91/binarytree/ 数据结构 首先我们定义需要的数据结构.注意,TreeNode的左右节点都是*TreeNod ...

  2. BUPT 2012复试机考 4T

    题目描述 我们都学习过计算机网络,知道网络层IP协议数据包的头部格式如下: 其中IHL表示IP头的长度,单位是4字节:总长表示整个数据包的长度,单位是1字节.传输层的TCP协议数据段的头部格式如下:  ...

  3. php 中函数获取可变参数的方法, 这个语法有点像 golang 语言中的

    原文呢:http://php.net/manual/en/functions.arguments.php#functions.arguments.type-declaration.strict Onl ...

  4. MBProgressHUD 显示方向异常

    一直在iphone上使用MBProgressHUD做提示信息视图.一直都没有什么问题,但用在ipad上使用时.却有时会出现显示方向不正常.如ipad屏幕是横的,但当MBProgressHUD出现时却依 ...

  5. 删除DataGridView选中行并更新数据库

    前面写过一篇文章是DataGridView控件显示数据的,DataGridView在与数据库打交道时会常常出现,也非常有用.通过DataGridView对数据库进行更改和查询都比較方便. 这里我们须要 ...

  6. SpringBoot学习之快速入门创建

    maven构建项目 1.访问http://start.spring.io/,进入快速创建工程的主页 可参考下图所示: 2.选择构建工具Maven Project.Spring Boot版本1.3.6以 ...

  7. RecyclerView(替代ListView)使用方法介绍

    在build.gradle文件加入以下代码 compile 'com.android.support:cardview-v7:21.0.3' compile 'com.android.support: ...

  8. 用NHibernate处理带属性的多对多关系

    1.引言 老谭在面试开发者的时候,为了考察他们的数据库开发能力,经常祭出我的法宝,就是大学数据库教程中讲到的一个模式:学生选课.这个模式是这种: 在这个模式中,学生(Student)和课程(Cours ...

  9. python day- 6 is 和 ==的区别 encode 和 decode

    1.is 和  == 的区别. == 是由来判断左右两边的内容是否相等. is 是用来判断内存地址是否相同. 引进 id (   )函数 小数据池: 对于字符串 ,数字 ,bool 值进行 id()计 ...

  10. cocos2d-x交叉编译到安卓

    ccocos2d-x是一个基于MIT协议的开源框架,用于构建游戏.应用程序和其它图形界面交互应用. 它的最大特点就是跨平台性,支持IOS, Android.Windows, WindowsPhone等 ...