欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

简单的四色问题

程序员文章站 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;
}
相关标签: c++