今天花了我四个小时写了一个练练自动解算程序, 广度 双向交替
效率还行 100*100巨大矩阵,给出6个不同的随机id的话 5秒内跑完
直接上代码
#include <iostream>
#include <string>
#include <cstring>
#include <queue>
#include <vector>
using namespace std;
const int ROW=9; //矩阵行数,测试的时候请改变配置
const int COLUMN=9; //矩阵列数,测试的时候可以改变
const int level=3; //id的个数,测试的时候可以改变
int L[ROW][COLUMN]; //二维数组
/*布局连连看*/
void laylout()
{
for(int i=0;i<ROW;i++)
for(int j=0;j<COLUMN;j++)
{
L[i][j]=(i*ROW+j)%level+1; //确保偶数成对填充
}
for(int i=0;i<ROW;i++)
for(int j=0;j<COLUMN;j++)
{
int n=rand()%ROW;
int m=rand()%COLUMN;
int temp=L[n][m]; //随机交换
L[n][m]=L[i][j];
L[i][j]=temp;
}
}
void show()
{
for(int i=0;i<ROW;i++)
{
for(int j=0;j<COLUMN;j++)
{
cout<<L[i][j]<<" ";
}
cout<<endl;
}
}
struct Point{
int x; //行
int y; //列
string path;
void pathadd(string PrePath)
{
char t=x+'0';
char tt=y+'0';
path=PrePath+" "+"("