简单的四色问题
程序员文章站
2022-05-20 22:51:21
...
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
const int N=6; //地图块数
char name[N][10]={"NAME1","NAME2","NAME3","NAME4","NAME5","NAME6"};
int c[N]={1};
int a[N][N]={ //连通情况
{0,1,0,0,0,0},
{1,0,1,0,1,1},
{0,1,0,1,1,0},
{0,0,1,0,0,0},
{0,1,1,0,0,1},
{0,1,0,0,1,0}};
int i,j,k,flag;
int (*p)[N];
p=a;
for(i=1;i<N;i++)
{
for(j=1;j<=4;j++)
{
flag=0;
for(k=0;k<=i-1;k++)
{
if(p[i][k]==1&&c[k]==j)
{
flag=1;
break;
}
}
if(!flag)
{
c[i]=j;
break;
}
}
}
for(i=0;i<N;i++)
cout<<name[i]<<" "<<c[i]<<endl;
cout<<endl;
return 0;
}
上一篇: 蓝桥杯之迷宫