UVALive 3401 Colored Cubes
2015-09-06 17:26
232 查看
其实题目不算难 就是麻烦一些 尤其是当你手推24组旋转的的时候...其实从{0,1,2,3,4,5}旋转的结果是有一点规律可循的 首先你先选出正面 即第一个数 第二个数就只有4种选择 然后从图中找出第三个数 剩下的3个数 其实已经固定了 因为立方体无论怎么旋转 0和5永远是相对的 所以0在3位置 5就一定在4位置 所以得出以3.5为轴 对应位置和为5 这样就能稍微好推点 说了这么多 然而并没有什么卵用 我还是推错了(>﹏<) 然后懒得找是哪推错了 就在网上复制了一份数组 所以还是建议大家像刘汝佳那样编一份代码来弄
不容易出错(不过对我来说编代码来推 肯定更慢 更容易出错(>﹏<)) 旋转的问题解决后 其他的就好办了 用map处理的编号 dfs跑出除第一个以外 其他的旋转姿势 然后暴力的跑出ans即可
不容易出错(不过对我来说编代码来推 肯定更慢 更容易出错(>﹏<)) 旋转的问题解决后 其他的就好办了 用map处理的编号 dfs跑出除第一个以外 其他的旋转姿势 然后暴力的跑出ans即可
#include<iostream> #include<cstdio> #include<cstring> #include<cctype> #include<cmath> #include<vector> #include<queue> #include<map> #include<algorithm> #include<set> #define scnaf scanf #define cahr char #define bug puts("bugbugbug"); using namespace std; typedef long long ll; const int mod=1000000007; const int maxn=10000+5; const int inf=1e9; int rota[24][10]= { //按照正右上 下左后 排列 确定好前3个后 以3.5为轴 和为5 { 0, 1, 2, 3, 4, 5 }, { 0, 2, 4, 1, 3, 5 }, { 0, 4, 3, 2, 1, 5 }, { 0, 3, 1, 4, 2, 5 }, { 3, 1, 0, 5, 4, 2 }, { 3, 0, 4, 1, 5, 2 }, { 3, 4, 5, 0, 1, 2 }, { 3, 5, 1, 4, 0, 2 }, { 5, 1, 3, 2, 4, 0 }, { 5, 3, 4, 1, 2, 0 }, { 5, 4, 2, 3, 1, 0 }, { 5, 2, 1, 4, 3, 0 }, { 2, 1, 5, 0, 4, 3 }, { 2, 5, 4, 1, 0, 3 }, { 2, 4, 0, 5, 1, 3 }, { 2, 0, 1, 4, 5, 3 }, { 4, 0, 2, 3, 5, 1 }, { 4, 2, 5, 0, 3, 1 }, { 4, 5, 3, 2, 0, 1 }, { 4, 3, 0, 5, 2, 1 }, { 1, 0, 3, 2, 5, 4 }, { 1, 3, 5, 0, 2, 4 }, { 1, 5, 2, 3, 0, 4 }, { 1, 2, 0, 5, 3, 4 } }; int a[10][10]; int b[10][10]; int cnt,ans,n; map<string, int >mp; void init() { cnt=1; ans=inf; mp.clear(); } void READ(int& z) { string b; cin>>b; if(mp[b]==0) mp[b]=cnt++; z=mp[b]; } void go() { int sum=0; for(int j=0; j<6; j++) { int visit[30]= {0}; for(int i=0; i<n; i++) { int z=b[i][j]; visit[z]++; } int maxx=0; for(int i=0; i<=24; i++) maxx=max(maxx,visit[i]); sum+=n-maxx; } ans=min(ans,sum); } void change(int id,int i) { for(int j=0; j<6; j++) b[id][j]=a[id][rota[i][j]]; } void dfs(int id) { if(id==n) { go(); return; } for(int i=0; i<24; i++) { change(id,i); dfs(id+1); } } int main() { while(scanf("%d",&n)&&n) { init(); for(int i=0; i<n; i++) for(int j=0; j<6; j++) READ(a[i][j]); for(int i=0; i<6; i++) b[0][i]=a[0][i]; dfs(1); printf("%d\n",ans); } }
相关文章推荐
- 123
- 手机游戏中的社交互动与任务剧情
- Delphi : Analyze PE file headers?
- IOS第18天(6,CAKeyframeAnimation关键帧动画)
- 如何用photoshop输出html网页
- linux内核中经常用到的设备初始化宏
- 关于自动化脚本黑盒话的进度
- 微信支付
- BestCoder Round #54
- css 多个不定数量提交按钮居中显示,纯css解决
- 如何实例化i2c_client(四法)
- 二叉树java实现
- Calendar:计算两个日期相差的天数
- ViewPager最简单的用法
- Linux下调整JBoss的JVM内存大小
- 理解oo:继承、多态、重写、重载、接口、抽象类
- 树的相关术语
- How to tell if a file is an EXE or a DLL?
- java中解析excel(扩展)
- zabbix系列(一):服务端安装与汉化