我试图为每个状态指定一种颜色,以便没有两个相邻的状态共享相同的颜色(http://en.wikipedia.org/wiki/Four_color_theorem).程序将输出每个状态及其颜色.
我正在读取一个文本文件,其格式为48个状态(2个未连接):
al,fl,ms,tn,ga
ar,la,tx,ok,mo,tn,ms
az,ca,nv,ut,nm
ca,az,nv,or
co,wy,ut,nm,ok,ks,ne
...
Run Code Online (Sandbox Code Playgroud)
例:
阿拉巴马州接触佛罗里达州,密西西比州,田纳西州和佐治亚州.
阿肯色州接触路易斯安那州,德克萨斯州等.
到目前为止这是我的代码:
MapColor.java
import java.io.*;
import java.util.*;
public class MapColor {
public static void main(String[] args) throws IOException {
ArrayList <String> statestemp = new ArrayList <String> ();
ArrayList <State> states = new ArrayList <State> ();
// read in each line
BufferedReader reader = new BufferedReader(new FileReader("usa.txt"));
String line = null;
while ((line = reader.readLine()) != null) {
statestemp.add(line);
}
reader.close();
// create all state objects and adjacencies
for …Run Code Online (Sandbox Code Playgroud)