UVALive 3401 Colored Cubes
来源:互联网 发布:阿里云api怎么解析 编辑:程序博客网 时间:2024/05/16 16:17
其实题目不算难 就是麻烦一些 尤其是当你手推24组旋转的的时候...其实从{0,1,2,3,4,5}旋转的结果是有一点规律可循的 首先你先选出正面 即第一个数 第二个数就只有4种选择 然后从图中找出第三个数 剩下的3个数 其实已经固定了 因为立方体无论怎么旋转 0和5永远是相对的 所以0在3位置 5就一定在4位置 所以得出以3.5为轴 对应位置和为5 这样就能稍微好推点 说了这么多 然而并没有什么卵用 我还是推错了(>﹏<) 然后懒得找是哪推错了 就在网上复制了一份数组 所以还是建议大家像刘汝佳那样编一份代码来弄 不容易出错(不过对我来说编代码来推 肯定更慢 更容易出错(>﹏<)) 旋转的问题解决后 其他的就好办了 用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); }}
0 0
- UVALive 3401 Colored Cubes
- UVALive - 3401 Colored Cubes
- UVALive - 3401 Colored Cubes
- UVALive 3401 Colored Cubes
- UVALive - 3401 Colored Cubes 枚举
- uvaLive 3401 Colored Cubes 暴力
- UVaLive 3401 Colored Cubes 彩色立方体
- 例题1.8 彩色立方体 Colored Cubes UVALive
- LA 3401 - Colored Cubes
- LA 3401 - Colored Cubes
- 3401 - Colored Cubes
- LA 3401 Colored Cubes
- UVa-3401 Colored Cubes
- LA 3401 Colored Cubes 暴力 -
- Colored Cubes
- Colored Cubes
- Colored Cubes
- HOJ The Colored Cubes
- 输出中文数据
- java web 通过ip获取当前地理位置
- Android Handler 四个使用实例 及HandlerThread的使用
- 腾讯2014校招笔试---软件开发A1
- 飞鱼星路由器常见问题解答
- UVALive 3401 Colored Cubes
- std::priority_queue
- 2015-0906-osg学习历程6
- C#综合揭秘——细说多线程(上)
- pt-table-checksum
- onMeasure流程,MeasureSpec详解
- [DS][Hash][PAT][Hashing]
- Spring AspectJ AOP 完整示例
- 2014-2015年终总结