33属地(2)79(3)117(4)

来源:互联网 发布:网络性能指标 编辑:程序博客网 时间:2024/05/05 22:18

智力游戏





规则和1属地(1)差不多,但是从3*3变成了3*4


1 2 5 0
1 2 3 4 0
1 2 3 4 0
3 4 8 0
1 5 9 0
2 5 6 7 10 0
3 6 7 8 11 0
4 8 12 0
5 9 10 0
9 10 11 12 0
9 10 11 12 0
8 11 12 0

根据这个规则,要过关很容易,但是要总结成固定的攻略就比较繁琐了。
所以我干脆编程解决。
这么做的很重要的一个原因是,每个格子只有3种状态,所以全局也只有3^12=531441种状态,所以可以用枚举法求出答案。
代码:
#include<iostream>using namespace std;int main(){int list[12][12];for (int i = 0; i < 12; i++)for (int j = 0; j < 12; j++)list[i][j] = 0;cout << "输入每个格子影响哪些格子,用0表示输入完毕" << endl;for (int i = 0; i < 12; i++){int a;for (int j = 0; j < 12; j++){cin >> a;if (a>0)list[a - 1][i] = 1;else break;}}int color[12];cout << "输入每个格子需要变化几次才能复原" << endl;for (int i = 0; i < 12; i++)cin >> color[i];
for (int x1 = 0; x1 < 3; x1++)for (int x2 = 0; x2 < 3; x2++)for (int x3 = 0; x3 < 3; x3++)for (int x4 = 0; x4 < 3; x4++)for (int x5 = 0; x5 < 3; x5++)for (int x6 = 0; x6 < 3; x6++)for (int x7 = 0; x7 < 3; x7++)for (int x8 = 0; x8 < 3; x8++)for (int x9 = 0; x9 < 3; x9++)for (int xa = 0; xa < 3; xa++)for (int xb = 0; xb < 3; xb++)for (int xc = 0; xc < 3; xc++)
{bool flag = true;for (int i = 0; i < 12; i++){int s = list[i][0] * x1 + list[i][1] * x2 + list[i][2] * x3 + list[i][3] * x4 + list[i][4] * x5 + list[i][5] * x6 + list[i][6] * x7 + list[i][7] * x8 + list[i][8] * x9 + list[i][9] * xa + list[i][10] * xb + list[i][11] * xc;if ((s - color[i]) % 3 != 0){flag = false;break;}}if (flag){cout << "下面是每个格子需要点击的次数" << endl;cout << x1 << x2 << x3 << x4 << endl;cout << x5 << x6 << x7 << x8 << endl;cout << x9 << xa << xb << xc;cout << endl << endl << "end";system("pause>nul");return 0;}}}

示例:


793


规则和上面的33属地(2)不一样,具体如下:

影响矩阵是:

1 6 11 0

2 7 12 0

3 6 9 0

4 7 10 0

1 5 9 0

2 5 6 7 10 0

3 6 7 8 11 0

4 8 12 0

3 6 9 0

4 7 10 0

1 6 11 0

2 7 12 0

蓝色是0,绿色是1,红色是2

运行上面的程序即可得到答案




1174


影响矩阵是:

1 5 9 10 0

2 6 9 10 0

3 7 11 12 0

4 8 11 12 0

3 5 6 7 0

4 6 7 8 0

1 5 6 7 0

2 3 4 8 0

7 9 10 11 0

2 3 6 10 0

3 4 7 11 0

6 7 8 12 0

淡黄色是0,绿色是1,红色是2

运行上面的程序即可得到答案



1 0
原创粉丝点击