Algorithm 如何制作这种模式发现算法?
我有一个矩阵,我需要在这个矩阵中找到一个模式。 矩阵为:Algorithm 如何制作这种模式发现算法?,algorithm,math,statistics,pattern-matching,Algorithm,Math,Statistics,Pattern Matching,我有一个矩阵,我需要在这个矩阵中找到一个模式。 矩阵为: 1 0 0 1 1 1 0 0 0 1 0 0 0 1 1 0 1 0 0 1 0 1 1 1 0 0 0 1 0 1 1 0 1 0 0 1 1 0 1 0 1 1 1 0 0 0 1 1 0 1 0 1 0 0 1 1 0 1 0 1 1 1 1 0 0 0 1 0 0 1 1 0 0 1 0 1 1 1 0 1 规则: 我们从每行中选择一个数字 第二行的下一个choosen编号必须与前一行相反 由1和2规则选择的数字位置必须是精确
1 0 0 1 1 1 0 0 0 1
0 0 0 1 1 0 1 0 0 1
0 1 1 1 0 0 0 1 0 1
1 0 1 0 0 1 1 0 1 0
1 1 1 0 0 0 1 1 0 1
0 1 0 0 1 1 0 1 0 1
1 1 1 0 0 0 1 0 0 1
1 0 0 1 0 1 1 1 0 1
规则:
int firstPos, secondPos;
for(int i = 0; i < 10; ++i)
if(matrix[0][i] == 0)
firstPos = i;
for(int i = 0; i < 10; ++i)
if(matrix[0][i] == 1)
secondPos= i;
bool success = true;
for(int i = 0; i < 10/2; ++i)
if(matrix[2*i][firstPos] == matrix[2*i][secondPos])
success == false;
if(success)
cout << "success" << endl;
else
cout << "failure" << endl;
int-firstPos,secondPos;
对于(int i=0;i<10;++i)
if(矩阵[0][i]==0)
firstPos=i;
对于(int i=0;i<10;++i)
if(矩阵[0][i]==1)
secondPos=i;
布尔成功=真;
对于(int i=0;i<10/2;++i)
if(矩阵[2*i][firstPos]==矩阵[2*i][secondPos])
成功==错误;
如果(成功)
cout我将通过第一项(F)的索引和第二项(S)的索引来定义模式。我还假设索引以0开头(而不是像您的示例中的1)。F和S都可以取0到9之间的值。解决办法很简单。有一个从0到9运行F和S的双嵌套循环,在第三个最内层循环中,只需验证当前F和S是否形成一个模式。您已经“创建”了算法。我不明白你为什么不用你最喜欢的编程语言编写你的指令列表并继续下去。如果您陷入困境,或者您认为您的算法是次优的(在某种意义上),请再次发布您的代码,我们将提供一些帮助。