欲求四色定理源程序流程图!!!!!
来源:百度知道 编辑:UC知道 时间:2024/07/07 20:52:29
在这里先. 谢谢了!!!
源程序: #include<stdio.h>
#define N 10
void output(int color[])/*输出一种着色方案*/
{ int i ;
for ( i = 0 ; i < N ; i++ )
printf( "%4d" , color[i] ) ;
printf( "\n" ) ;
}
int back( int *ip ,int color[] ) /*回溯*/
{
int c = 4 ;
while ( c == 4 )
{
if ( *ip <= 0 )
return 0 ;
--(*ip) ;
c = color[*ip];
color[*ip] = -1 ;
}
return c ;
}
/*检查区域i,对c种颜色的可用性*/
int colorok( int i , int c , int adj[][N] , int color[ ] )
{
int j ;
for ( j = 0 ; j < i ; j++ )
if (adj[i][j] != 0 && color[j] == c)
return 0 ;
return 1 ;
}
源程序: #include<stdio.h>
#define N 10
void output(int color[])/*输出一种着色方案*/
{ int i ;
for ( i = 0 ; i < N ; i++ )
printf( "%4d" , color[i] ) ;
printf( "\n" ) ;
}
int back( int *ip ,int color[] ) /*回溯*/
{
int c = 4 ;
while ( c == 4 )
{
if ( *ip <= 0 )
return 0 ;
--(*ip) ;
c = color[*ip];
color[*ip] = -1 ;
}
return c ;
}
/*检查区域i,对c种颜色的可用性*/
int colorok( int i , int c , int adj[][N] , int color[ ] )
{
int j ;
for ( j = 0 ; j < i ; j++ )
if (adj[i][j] != 0 && color[j] == c)
return 0 ;
return 1 ;
}
流程图我就不画了,说一下大概吧。
这是一个递归与循环的嵌套。
用循环对每一个地图格的周围三个格子进行搜索。
(周围共四个格子,其中一个是初始格)
对于每一次搜索,再用递归进行下一层的搜索。
这样循环并递归下去,就能对整幅地图充分搜索了。