地图着色问题
Posted 小喽啰A
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了地图着色问题相关的知识,希望对你有一定的参考价值。
package com.ds;
import java.util.Random;
/**
* Created by developer on 2016/5/9.
*/
public class DrawMapColor
public static void main(String[] args)
Node[] nodes = new Node[]new Node(), new Node(), new Node(), new Node(), new Node(), new Node();
// 关系表
int[][] nn = new int[][]
//A, B, C, D, E, F
0, 1, 1, 1, 1, 0, // A
1, 0, 1, 0, 1, 1, // B
1, 1, 0, 1, 0, 0, // C
1, 0, 1, 0, 1, 0, // D
1, 1, 0, 1, 0, 1, // E
0, 1, 0, 0, 1, 0 // F
;
Color[] colors = new Color[] Color.BLACK, Color.BLUE, Color.GREEN, Color.RED;
Node A = nodes[0];
A.color = colors[0];
for (int i=1; i < nodes.length; ++i)
Node next = nodes[i];
//Color colorTemp = colors[0];
int[] rels = nn[i];
for (;;)
Random r = new Random(System.currentTimeMillis());
int rx = r.nextInt() % 3;
if (rx < 0) rx = -rx;
Color colorTemp = colors[rx];
int tag = 1;
for (int j = 0; j < rels.length; ++j)
if (rels[j] == 1 && nodes[j].color == colorTemp)
tag = 0;
break;
if (tag == 1)
next.color = colorTemp;
break;
for (Node node: nodes)
System.out.print(node.color + "\\t");
以上是关于地图着色问题的主要内容,如果未能解决你的问题,请参考以下文章