清北NOIP集训营内部试题-魔方

网友投稿 2019-11-05 14:01

摘要

     本题为往年清北学堂NOIP集训营内部测试题。供大家学习参考!更多信息学课程培训请电话或留言咨询!

01

题目

https://cdn.china-scratch.com/timg/191107/14012455I-0.jpg

https://cdn.china-scratch.com/timg/191107/140125F52-1.jpg

题面有误!10,11,12操作类别为A,13,14,15类别为B,16,17,18类别为C.

结题思路在代码后面。 

https://cdn.china-scratch.com/timg/191107/1401252b3-2.jpg

#include
#include
#include
#include
using namespace std;
int n, ans[10], cnt, c[30];
bool stop = false;
void turn1()
{
int tmp, tmp2;
tmp = c[1];
c[1] = c[3];
c[3] = c[4];
c[4] = c[2];
c[2] = tmp;
tmp = c[23];
tmp2 = c[24];
c[23] = c[10];
c[24] = c[9];
c[9] = c[5];
c[10] = c[6];
c[5] = c[13];
c[6] = c[14];
c[13] = tmp2;
c[14] = tmp;
}
void turn2()
{
int tmp,tmp2;
tmp = c[9];
c[9] = c[11];
c[11] = c[12];
c[12] = c[10];
c[10] = tmp;
tmp = c[1];
tmp2 = c[3];
c[1] = c[21];
c[3] = c[23];
c[23] = c[19];
c[21] = c[17];
c[19] = c[7];
c[17] = c[5];
c[7] = tmp2;
c[5] = tmp;
}
void turn3()
{
int tmp = c[5], tmp2;
c[5] = c[7];
c[7] = c[8];
c[8] = c[6];
c[6] = tmp;
tmp = c[17];
tmp2 = c[18];
c[17] = c[15];
c[18] = c[13];
c[15] = c[4];
c[13] = c[3];
c[3] = c[12];
c[4] = c[10];
c[10] = tmp;
c[12] = tmp2;
}
void turn4()
{
int tmp = c[13], tmp2;
c[13] = c[15];
c[15] = c[16];
c[16] = c[14];
c[14] = tmp;
tmp = c[6];
tmp2 = c[8];
c[6] = c[18];
c[8] = c[20];
c[18] = c[22];
c[20] = c[24];
c[22] = c[2];
c[24] = c[4];
c[2] = tmp;
c[4] = tmp2;
}
void turn5()
{
int tmp = c[21], tmp2;
c[21] = c[23];
c[23] = c[24];
c[24] = c[22];
c[22] = tmp;
tmp = c[19];
tmp2 = c[20];
c[19] = c[9];
c[20] = c[11];
c[9] = c[2];
c[11] = c[1];
c[1] = c[14];
c[2] = c[16];
c[14] = tmp2;
c[16] = tmp;
}
void turn6()
{
int tmp = c[17], tmp2;
c[17] = c[19];
c[19] = c[20];
c[20] = c[18];
c[18] = tmp;
tmp = c[21];
tmp2 = c[22];
c[21] = c[16];
c[22] = c[15];
c[16] = c[8];
c[15] = c[7];
c[8] = c[12];
c[7] = c[11];
c[12] = tmp;
c[11] = tmp2;
}
bool check()
{
return c[1] == c[2] && c[2] == c[3] && c[3] == c[4] &&
c[5] == c[6] && c[6] == c[7] && c[7] == c[8] &&
c[9] == c[10] && c[10] == c[11] && c[11] == c[12] &&
c[13] == c[14] && c[14] == c[15] && c[15] == c[16] &&
c[17] == c[18] && c[18] == c[19] && c[19] == c[20] &&
c[21] == c[22] && c[22] == c[23] && c[23] == c[24];
}
void dfs(int dep, int flag)
{
if (check())
{
cnt = dep;
stop = 1;
return;
}
if (dep >= n)
return;
if (flag != 1)
{
for (int i = 1; i <= 3; i++)
{
turn1();
ans[dep + 1] = i;
dfs(dep + 1, 1);
if (stop)
return;
}
turn1();
}
if (flag != 2)
{
for (int i = 1; i <= 3; i++)
{
turn2();
ans[dep + 1] = 3 + i;
dfs(dep + 1, 2);
if (stop)
return;
}
turn2();
}
if (flag != 3)
{
for (int i = 1; i <= 3; i++)
{
turn3();
ans[dep + 1] = 6 + i;
dfs(dep + 1, 3);
if (stop)
return;
}
turn3();
}
if (flag != 3)
{
for (int i = 1; i <= 3; i++)
{
turn4();
ans[dep + 1] = 9 + i;
dfs(dep + 1, 3);
if (stop)
return;
}
turn4();
}
if (flag != 2)
{
for (int i = 1; i <= 3; i++)
{
turn5();
ans[dep + 1] = 12 + i;
dfs(dep + 1, 2);
if (stop)
return;
}
turn5();
}
if (flag != 1)
{
for (int i = 1; i <= 3; i++)
{
turn6();
ans[dep + 1] = 15 + i;
dfs(dep + 1, 1);
if (stop)
return;
}
turn6();
}
}
int main()
{
scanf("%d", &n);
for (int i = 1; i <= 24; i++)
scanf("%d", &c[i]);
dfs(0, 0);
for (int i = 1; i <= cnt; i++)
printf("%d ", ans[i]);
return 0;
}

解析:一道大暴力,每次记录一下走了多少步,上一步操作类别是啥就可以了.最后只需要写6种操作,每一次操作进行4次就还原了,所以不用memcpy再来转.

--end--

声明:本文章由网友投稿作为教育分享用途,如有侵权原作者可通过邮件及时和我们联系删除:freemanzk@qq.com