K - Pocket Cube

Time Limit:10000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Description

Pocket Cube is a 3-D combination puzzle. It is a 2 × 2 × 2 cube, which means it is constructed by 8 mini-cubes. For a combination of 2 × 2 mini-cubes which sharing a whole cube face, you can twist it 90 degrees in clockwise or counterclockwise direction, this twist operation is called one twist step. 
Considering all faces of mini-cubes, there will be totally 24 faces painted in 6 different colors (Indexed from 0), and there will be exactly 4 faces painted in each kind of color. If 4 mini-cubes' faces of same color rely on same large cube face, we can call the large cube face as a completed face.

Now giving you an color arrangement of all 24 faces from a scrambled Pocket Cube, please tell us the maximum possible number of completed faces in no more than N twist steps. 
Index of each face is shown as below:

 

Input

There will be several test cases. In each test case, there will be 2 lines. One integer N (1 ≤ N ≤ 7) in the first line, then 24 integers Ci separated by a single space in the second line. For index 0 ≤ i < 24, Ci is color of the corresponding face. We guarantee that the color arrangement is a valid state which can be achieved by doing a finite number of twist steps from an initial cube whose all 6 large cube faces are completed faces.
 

Output

For each test case, please output the maximum number of completed faces during no more than N twist step(s).
 

Sample Input

1
0 0 0 0 1 1 2 2 3 3 1 1 2 2 3 3 4 4 4 4 5 5 5 5
1
0 4 0 4 1 1 2 5 3 3 1 1 2 5 3 3 4 0 4 0 5 2 5 2
 

Sample Output

6
2
 
转魔方,bfs,一直找不到wa在哪里。这题思考魔方的旋转有点烦。
有6种旋转方式,而不是12种。。
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<vector>
  5. #include<queue>
  6. #include<algorithm>
  7. #include<map>
  8. #define INF 0x3f3f3f3f
  9. #define M(a,b) memset(a,b,sizeof(a))
  10.  
  11. using namespace std;
  12.  
  13. int state[];
  14. int change[][]={
  15. {,,,,,,,,,,,,,,,,,,,,,,,},
  16. {,,,,,,,,,,,,,,,,,,,,,,,},
  17. {,,,,,,,,,,,,,,,,,,,,,,,},
  18. {,,,,,,,,,,,,,,,,,,,,,,,},
  19. {,,,,,,,,,,,,,,,,,,,,,,,},
  20. {,,,,,,,,,,,,,,,,,,,,,,,},
  21. };
  22.  
  23. int N;
  24. int ans;
  25.  
  26. struct tube
  27. {
  28. int d[];
  29. int cnt;
  30. tube(){}
  31. };
  32. tube st;
  33. tube trans(tube tmp,int k)
  34. {
  35. tube res;
  36.  
  37. for (int i=; i<; i++)
  38. res.d[i]=tmp.d[change[k][i]];
  39.  
  40. return res;
  41. }
  42. int count(tube tmp)
  43. {
  44. int res=;
  45. if (tmp.d[]==tmp.d[] && tmp.d[]==tmp.d[] && tmp.d[]==tmp.d[]) res++;
  46. if (tmp.d[]==tmp.d[] && tmp.d[]==tmp.d[] && tmp.d[]==tmp.d[]) res++;
  47. if (tmp.d[]==tmp.d[] && tmp.d[]==tmp.d[] && tmp.d[]==tmp.d[]) res++;
  48. if (tmp.d[]==tmp.d[] && tmp.d[]==tmp.d[] && tmp.d[]==tmp.d[]) res++;
  49. if (tmp.d[]==tmp.d[] && tmp.d[]==tmp.d[] && tmp.d[]==tmp.d[]) res++;
  50. if (tmp.d[]==tmp.d[] && tmp.d[]==tmp.d[] && tmp.d[]==tmp.d[]) res++;
  51. return res;
  52. }
  53.  
  54. void bfs()
  55. {
  56. queue<tube> q;
  57. q.push(st);
  58. // map<tube,int> mp;
  59. // mp[st]=1;
  60. ans=count(st);
  61. while(!q.empty())
  62. {
  63. tube now=q.front();
  64. q.pop();
  65. tube tmp;
  66. for (int i=; i<; i++)
  67. {
  68. tmp=trans(now,i);
  69. tmp.cnt=now.cnt+;
  70. // if (mp.find(tmp)!=mp.end())
  71. // {
  72. // mp[tmp]=1;
  73. // ans=max(ans,count(tmp));
  74. // if (tmp.cnt<num) q.push(tmp);
  75. // }
  76. ans=max(ans,count(tmp));
  77. if (tmp.cnt<N) q.push(tmp);
  78. }
  79. }
  80. }
  81.  
  82. int main()
  83. {
  84. //init();
  85. while(scanf("%d",&N)==)
  86. {
  87. for(int i = ;i<;i++)
  88. {
  89. scanf("%d",&st.d[i]);
  90. }
  91. st.cnt=;
  92. bfs();
  93. printf("%d\n",ans);
  94. }
  95. return ;
  96. }

2013区域赛长沙赛区现场赛 K - Pocket Cube的更多相关文章

  1. 2014年亚洲区域赛北京赛区现场赛A,D,H,I,K题解(hdu5112,5115,5119,5220,5122)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud 下午在HDU上打了一下今年北京区域赛的重现,过了5题,看来单挑只能拿拿铜牌,呜呜. ...

  2. HDU 4793 Collision (解二元一次方程) -2013 ICPC长沙赛区现场赛

    题目链接 题目大意 :有一个圆硬币半径为r,初始位置为x,y,速度矢量为vx,vy,有一个圆形区域(圆心在原点)半径为R,还有一个圆盘(圆心在原点)半径为Rm (Rm < R),圆盘固定不动,硬 ...

  3. 2013长沙赛区现场赛 J - Josephina and RPG

    J - Josephina and RPG Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I6 ...

  4. ACM-ICPC 2017 西安赛区现场赛 K. LOVER II && LibreOJ#6062. 「2017 山东一轮集训 Day2」Pair(线段树)

    题目链接:西安:https://nanti.jisuanke.com/t/20759   (计蒜客的数据应该有误,题目和 LOJ 的大同小异,题解以 LOJ 为准)     LOJ:https://l ...

  5. 擦肩而过的那块牌--记ACM_ICPC西安赛区现场赛

    说了那么多次orz,这次是真的orz了.去了西安打区域赛,也想过会打铁.但当终于那一刻确定打铁了之后.心里还是非常不开心的,颁奖的时候思考熊那家伙嚣张的举起来手中那个金杯,说实话闪到我眼了(太亮了QA ...

  6. 2014 ACM/ICPC 鞍山赛区现场赛 D&amp;I 解题报告

    鞍山现场赛结束了呢-- 我们出的是D+E+I三道题-- 吾辈AC掉的是D和I两道,趁着还记得.先在这里写一写我写的两道水题D&I的解题报告吧^_^. D题的意思呢是说星云内有一堆排成一条直线的 ...

  7. ACM总结——2017ACM-ICPC北京赛区现场赛总结

    现在距离比赛结束已经过了一个多星期了,也是终于有时间写下心得了.回来就是被压着做项目,也是够够的. 这次比赛一样是我和两个学弟(虽然是学弟,但我的实力才是最弱的T_T)一起参加的,成绩的话打铁,算是情 ...

  8. 2013 ACM区域赛长沙 K Pocket Cube hdu 4801

    题意:给了一个2*2的魔方..每步操作可以将任意一面翻转90度..现在问在N(<=7)步内.最多能翻出几面相同的. 直接打表模拟每种翻转情况 #include<cstdio> #in ...

  9. ACM-ICPC 2018 青岛赛区现场赛 K. Airdrop && ZOJ 4068 (暴力)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4068 题意:吃鸡游戏简化为二维平面上有 n 个人 (xi,yi) ...

随机推荐

  1. django 快速搭建blog

    如果本文看不懂的,去看的我视频吧!http://www.testpub.cn/ ------------------------------------------- Django 自称是“最适合开发 ...

  2. CentOS设置防火墙开放端口

    1. iptables是linux下的防火墙,同时也是服务的名称. service iptables status service iptables start service iptables st ...

  3. ubuntu下的ssh

    ubuntu默认是没有安装openssh-server的,今天简单的写一下ubuntu上ssh的安装与使用. 一.服务器端 安装 apt-get install openssh-server #安装 ...

  4. 一键搭建vpn服务器

    今天花了很多时间搭建vpn服务器,后来找到一篇一键搭建服务器的文章,那叫一个爽,附上链接收藏~~~看开以后要写脚本了 http://www.centoscn.com/image-text/instal ...

  5. HTML中<meta>标签如何正确使用

    HTML中<meta>标签如何正确使用 如果我们在浏览器中按下F12或者Ctrl+shift+J,便可以打开开发者工具,在element中即可看到<head>元素中有不少< ...

  6. Docker入门教程(九)10个镜像相关的API

    Docker入门教程(九)10个镜像相关的API [编者的话]DockerOne组织翻译了Flux7的Docker入门教程,本文是系列入门教程的第九篇,重点介绍了镜像相关的Docker Remote ...

  7. PHP-权限控制类

    http://blog.csdn.net/painsonline/article/details/7183679 <?php /** * 权限控制类 */ class include_purvi ...

  8. vs------连接MySQL

    转载: http://jingyan.baidu.com/article/8ebacdf023953f49f65cd589.html

  9. JavaScript 的性能优化:加载和执行

    随着 Web2.0 技术的不断推广,越来越多的应用使用 javascript 技术在客户端进行处理,从而使 JavaScript 在浏览器中的性能成为开发者所面临的最重要的可用性问题.而这个问题又因 ...

  10. VC----Class Style类风格和窗口风格

    CS_BYTEALIGNCLIENT:以字节边界来对齐窗口客户区,这个风格会影响 窗口 的宽度和水平位置.实际上没有看到效果. CS_BYTEALIGNWINDOW:以字节边界来对齐窗口,这个风格会影 ...