日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

四色定理java_java – 四色定理的递归算法

發布時間:2023/12/20 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 四色定理java_java – 四色定理的递归算法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

手頭的問題是將地圖分成區域,如鄰接矩陣和

使用四種顏色,為地圖著色,使得沒有兩個連續區域共享相同的顏色.我們會用的

鄰接矩陣,用于編碼哪個區域與哪個其他區域接壤.列和行

矩陣是區域,而如果兩個區域不相鄰,則單元格包含0,如果是,則單元格包含1

邊界.創建一個遞歸回溯解決方案,該解決方案接受來自用戶的交互式輸入

地圖中的區域數量和表示地圖構成的鄰接矩陣的文件名.

我遇到的問題是countryColor中的第一個值被更改,但數組中的許多值永遠不會更改.

private static final int[] color = {1,2,3,4};

//this color array is meant to represent 4 colors like red, blue, green, orange etc.

private static int[][] map = {{0,1,1,0,1,1,0},{1,0,0,1,1,0,1},{1,0,0,1,1,1,0},{0,1,1,0,1,0,1},{1,1,1,1,0,0,0},{1,0,1,0,0,0,1},{0,1,0,1,0,1,0}};

//this is the adjacency matrix showing which countries are next to each other

private static int[] countryColor = new int[7];

//this is the array that holds the color values for each country

private static boolean colorMap(int country ){

System.out.println("Checking Country "+ country);

boolean check;

for(int j= 0;j< countryColor.length; j++){

if(useColor(country,color[j]) == true)

countryColor[country] = color[j];

if(country == countryColor.length-1)

return true;

check = colorMap(country+1);

System.out.println(check);

if(check == true)

return true;

countryColor[country]=0;

}

return false;

}

private static boolean useColor(int country, int color){

for(int i = 0; i < map.length;i++){

if(map[country][i] == 1&& countryColor[i]==color){

System.out.println("Nah country " + country +" cant be "+color );

return false;

}

}

return true;

}

總結

以上是生活随笔為你收集整理的四色定理java_java – 四色定理的递归算法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。