本文最后更新于 1163 天前,其中的信息可能已经有所发展或是发生改变。
#include<iostream>
#include<cstring>
using namespace std;
int arr_num[10][2];
int count=0;
int judge(int arr[3][4],int x,int y,int temp){
if(x-1>=0&&y-1>=0){
if(arr[x-1][y-1]==(temp-1)||arr[x-1][y-1]==(temp+1)){
//cout<<"11"<<endl;
return 0;
}
}
if(x-1>=0){
if(arr[x-1][y]==(temp-1)||arr[x-1][y]==(temp+1)){//cout<<"22"<<endl;
return 0;
}
}
if(x-1>=0&&y+1<4){
if(arr[x-1][y+1]==(temp-1)||arr[x-1][y+1]==(temp+1)){//cout<<"33"<<endl;
return 0;
}
}
if(y-1>=0){
if(arr[x][y-1]==(temp-1)||arr[x][y-1]==(temp+1)){//cout<<"44"<<endl;
return 0;
}
}
if(y+1<4){
if(arr[x][y+1]==(temp-1)||arr[x][y+1]==(temp+1)){//cout<<"55"<<endl;
return 0;
}
}
if(x+1<3&&y-1>=0){
if(arr[x+1][y-1]==(temp-1)||arr[x+1][y-1]==(temp+1)){//cout<<"66"<<endl;
return 0;
}
}
if(x+1<3){
if(arr[x+1][y]==(temp-1)||arr[x+1][y]==(temp+1)){//cout<<"77"<<endl;
return 0;
}
}
if(x+1<3&&y+1<4){
if(arr[x+1][y+1]==(temp-1)||arr[x+1][y+1]==(temp+1)){//cout<<"88"<<endl;
return 0;
}
}
return 1;
}
void dg(int arr[3][4],int x,int y){
if(x==2&&y==3){
for(int i=0;i<3;i++){
for(int j=0;j<4;j++){
cout<<arr[i][j]<<" ";
}
cout<<endl;
}
count++;
return;
}
for(int i=0;i<10;i++){
if(arr_num[i][1]==0){
//cout<<"i="<<i<<endl;
if(judge(arr,x,y,arr_num[i][0])){
arr_num[i][1]=1;
arr[x][y]=arr_num[i][0];
//cout<<"arr[x][y]=arr_num[i][0];"<<endl;
//cout<<"x:"<<x<<"y:"<<y<<"arr_num[i][0]:"<<arr_num[i][0]<<endl;
if(x==0){
if(y+1<4){
dg(arr,x,y+1);
}else{
dg(arr,1,0);
}
}else if(x==1){
if(y+1<4){
dg(arr,x,y+1);
}else{
dg(arr,2,0);
}
}else if(x==2){
if(y+1<4){
dg(arr,x,y+1);
}
}
arr_num[i][1]=0;
arr[x][y]=-5;
}
}
}
}
int main(){
int arr[3][4];
for(int i=0;i<10;i++){
arr_num[i][0]=i;
arr_num[i][1]=0;
cout<<arr_num[i][0]<<endl;
}
//memset(arr,-1,sizeof(arr));
for(int i=0;i<3;i++){
for(int j=0;j<4;j++){
arr[i][j]=-5;
}
}
arr[0][0]=-2;
arr[2][3]=-2;
// for(int i=0;i<3;i++){
// for(int j=0;j<4;j++){
// arr[]
// }
// }
dg(arr,0,1);
cout<<count<<endl;
return 0;
}
Post Views: 186