11多米诺骨牌(1)
【摘要】
智力游戏
这个是4*4的多米诺骨牌,规则类似幻方。
代码:
#include<iostream>
using namespace std;
int ifsame(int a, int b, int c, int d)//判断(a,b)和(c,d)是否相同
{
if (a =...
这个是4*4的多米诺骨牌,规则类似幻方。
代码:
#include<iostream> using namespace std; int ifsame(int a, int b, int c, int d)//判断(a,b)和(c,d)是否相同 { if (a == c && b == d || a == d && b == c)return 1; return 0; } int f(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8, int x9, int x10, int x11, int x12, int x13, int x14, int x15, int x16) 判断这8组有没有相同的 { int shuzu[16] = { x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16 }; for (int i = 0; i < 16; i += 2)for (int j = i + 2; j < 16; j += 2) if (ifsame(shuzu[i], shuzu[i + 1], shuzu[j], shuzu[j + 1]))return 0; return 1; } int main() { cout << "answer:" << endl; int n = 1; for (int i1 = 0; i1 < 7; i1++)for (int i2 = 0; i2 <= 6 - i1; i2++)for (int i3 = 0; i3 <= 6 - i1 - i2; i3++) for (int i4 = 0; i4 <= 6 - i1; i4++)for (int i5 = 0; i5 <= 6 - i4; i5++) for (int i6 = 0; i6 <= 6 - i4 - i5; i6++)for (int i7 = 0; i7 <= 6 - i1 - i4; i7++) { int i8 = i1 + i1 + i2 + i3 + i4 - i6 + i7 - 6; int temp = 18 - i1 - i1 - i2 - i3 - i4 - i5 - i5 - i6 - i7 - i8; if (temp % 2 == 0 && i8 >= 0 && temp >= 0) { int i9 = temp / 2, i10 = 6 - i1 - i2 - i3, i11 = 6 - i4 - i5 - i6, i12 = 6 - i7 - i8 - i9; int i13 = 6 - i1 - i4 - i7, i14 = 6 - i2 - i5 - i8, i15 = 6 - i3 - i6 - i9, i16 = 6 - i1 - i5 - i9; if (i14 >= 0 && i12 >= 0 && i15 >= 0 && i16 >= 0)if (f(i1, i4, i2, i5, i3, i6, i10, i11, i7, i13, i8, i14, i9, i15, i12, i16)) cout << n++ << " " << i1 << " " << i2 << " " << i3 << " " << i4 << " " << i5 << " " << i6 << " " << i7 << " " << i8 << " " << i9 << endl; } } cout << "一共有" << n-1 << "组"; system("pause > nul"); return 0; }
结果:
文章来源: blog.csdn.net,作者:csuzhucong,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/nameofcsdn/article/details/52746213
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)