7個國家首都與中國的首都連線,線段的交於中國地圖上,記為7個點,這幾個點彼此互不影響,互不重合,按照各自國家所占的貿易比例,同時進行分割地圖。 ...
問題:7個國家首都與中國的首都連線,線段的交於中國地圖上,記為7個點,這幾個點彼此互不影響,互不重合,按照各自國家所占的貿易比例,同時進行分割地圖。
思路:利用深度,廣度遍歷均可。
1 package hccc01; 2 3 import java.awt.image.BufferedImage; 4 import java.io.File; 5 import java.io.IOException; 6 import java.util.ArrayList; 7 import java.util.Map; 8 9 import javax.imageio.ImageIO; 10 11 public class tree_map { 12 static ArrayList<String> list = tree_map1.getList(); 13 static Map<String, Integer> map = tree_map1.getMap(); 14 // 俄羅斯(255, 175, 175) 149697 2.7% 4686 173577 15 static ArrayList<String> A = new ArrayList<String>() { 16 { 17 add("351,210"); 18 } 19 }; 20 static int n_a = 0; 21 // 土耳其(255, 255, 0) 51664 0.2% 347 22 static ArrayList<String> B = new ArrayList<String>() { 23 { 24 add("279,299"); 25 } 26 }; 27 static int n_b = 0; 28 29 // 美國(255, 200, 0) 2689245 46.4% 80539 30 static ArrayList<String> C = new ArrayList<String>() { 31 { 32 add("244,317"); 33 } 34 }; 35 static int n_c = 0; 36 37 // 南韓(0, 255, 0) 778850 13.5% 23432 38 static ArrayList<String> D = new ArrayList<String>() { 39 { 40 add("784,322"); 41 } 42 }; 43 static int n_d = 0; 44 45 // 巴西(0, 255, 255) 1003099 17.3% 30028 46 static ArrayList<String> E = new ArrayList<String>() { 47 { 48 add("341,465"); 49 } 50 }; 51 static int n_e = 0; 52 // 澳大利亞(0, 0, 255) 1132923 19.6% 34021 53 static ArrayList<String> F = new ArrayList<String>() { 54 { 55 add("816,482"); 56 } 57 }; 58 static int n_f = 0; 59 60 // 坦桑利亞(255, 0, 255) 11501 0.3% 520 61 static ArrayList<String> G = new ArrayList<String>() { 62 { 63 add("459,512"); 64 } 65 }; 66 static int n_g = 0; 67 68 public static void main(String[] args) { 69 int n = 0; 70 for (; n < 60338; n++) { 71 // A點擴散 72 aSpread(n); 73 // B點擴散 74 bSpread(n); 75 cSpread(n); 76 dSpread(n); 77 eSpread(n); 78 fSpread(n); 79 gSpread(n); 80 } 81 82 // 擴散生成圖片 83 create(); 84 // for (String in : map.keySet()) { 85 // // map.keySet()返回的是所有key的值 86 // Integer str = map.get(in);// 得到每個key多對用value的值 87 // if (-65536==(str)) { 88 // System.out.println(str); 89 // } 90 // } 91 System.out.print("over"); 92 } 93 94 private static void gSpread(int n) { 95 if (n_g < 500) { 96 int pixel = 0; 97 int Xg = Integer.parseInt((G.get(n).split(","))[0]); 98 int Yg = Integer.parseInt((G.get(n).split(","))[1]); 99 String G1 = (Xg + 1) + "" + "," + Yg + ""; 100 String G2 = Xg + "" + "," + (Yg + 1) + ""; 101 String G3 = (Xg - 1) + "" + "," + Yg + ""; 102 String G4 = Xg + "" + "," + (Yg - 1) + ""; 103 String G5 = (Xg + 1) + "" + "," + (Yg + 1) + ""; 104 String G6 = (Xg + 1) + "" + "," + (Yg - 1) + ""; 105 String G7 = Xg + "" + "," + Yg + ""; 106 String G8 = (Xg - 1) + "" + "," + (Yg - 1) + ""; 107 String G9 = (Xg - 1) + "" + "," + (Yg + 1) + ""; 108 // 資源池包含G點,則進行染色,否則不做處理 109 if (list.contains(G1)) { 110 pixel = tree_map1.getPixel(255, 0, 255); 111 map.put(G1, pixel); 112 list.remove(G1); 113 G.add(G1); 114 n_g += 1; 115 } 116 if (list.contains(G2)) { 117 pixel = tree_map1.getPixel(255, 0, 255); 118 map.put(G2, pixel); 119 list.remove(G2); 120 G.add(G2); 121 n_g += 1; 122 } 123 if (list.contains(G3)) { 124 pixel = tree_map1.getPixel(255, 0, 255); 125 map.put(G3, pixel); 126 list.remove(G3); 127 G.add(G3); 128 n_g += 1; 129 } 130 if (list.contains(G4)) { 131 pixel = tree_map1.getPixel(255, 0, 255); 132 map.put(G4, pixel); 133 list.remove(G4); 134 G.add(G4); 135 n_g += 1; 136 } 137 if (list.contains(G5)) { 138 pixel = tree_map1.getPixel(255, 0, 255); 139 map.put(G5, pixel); 140 list.remove(G5); 141 G.add(G5); 142 n_g += 1; 143 } 144 if (list.contains(G6)) { 145 pixel = tree_map1.getPixel(255, 0, 255); 146 map.put(G6, pixel); 147 list.remove(G6); 148 G.add(G6); 149 n_g += 1; 150 } 151 if (list.contains(G7)) { 152 pixel = tree_map1.getPixel(255, 0, 255); 153 map.put(G7, pixel); 154 list.remove(G7); 155 G.add(G7); 156 n_g += 1; 157 } 158 if (list.contains(G8)) { 159 pixel = tree_map1.getPixel(255, 0, 255); 160 map.put(G8, pixel); 161 list.remove(G8); 162 G.add(G8); 163 n_g += 1; 164 } 165 if (list.contains(G9)) { 166 pixel = tree_map1.getPixel(255, 0, 255); 167 map.put(G9, pixel); 168 list.remove(G9); 169 G.add(G9); 170 n_g += 1; 171 } 172 } 173 } 174 175 private static void fSpread(int n) { 176 if (n_f < 40897) { 177 int pixel = 0; 178 int Xf = Integer.parseInt((F.get(n).split(","))[0]); 179 int Yf = Integer.parseInt((F.get(n).split(","))[1]); 180 String F1 = (Xf + 1) + "" + "," + Yf + ""; 181 String F2 = Xf + "" + "," + (Yf + 1) + ""; 182 String F3 = (Xf - 1) + "" + "," + Yf + ""; 183 String F4 = Xf + "" + "," + (Yf - 1) + ""; 184 String F5 = (Xf + 1) + "" + "," + (Yf + 1) + ""; 185 String F6 = (Xf + 1) + "" + "," + (Yf - 1) + ""; 186 String F7 = Xf + "" + "," + Yf + ""; 187 String F8 = (Xf - 1) + "" + "," + (Yf - 1) + ""; 188 String F9 = (Xf - 1) + "" + "," + (Yf + 1) + ""; 189 // 資源池包含F點,則進行染色,否則不做處理 190 if (list.contains(F1)) { 191 pixel = tree_map1.getPixel(0, 0, 255); 192 map.put(F1, pixel); 193 list.remove(F1); 194 F.add(F1); 195 n_f += 1; 196 } 197 if (list.contains(F2)) { 198 pixel = tree_map1.getPixel(0, 0, 255); 199 map.put(F2, pixel); 200 list.remove(F2); 201 F.add(F2); 202 n_f += 1; 203 } 204 if (list.contains(F3)) { 205 pixel = tree_map1.getPixel(0, 0, 255); 206 map.put(F3, pixel); 207 list.remove(F3); 208 F.add(F3); 209 n_f += 1; 210 } 211 if (list.contains(F4)) { 212 pixel = tree_map1.getPixel(0, 0, 255); 213 map.put(F4, pixel); 214 list.remove(F4); 215 F.add(F4); 216 n_f += 1; 217 } 218 if (list.contains(F5)) { 219 pixel = tree_map1.getPixel(0, 0, 255); 220 map.put(F5, pixel); 221 list.remove(F5); 222 F.add(F5); 223 n_f += 1; 224 } 225 if (list.contains(F6)) { 226 pixel = tree_map1.getPixel(0, 0, 255); 227 map.put(F6, pixel); 228 list.remove(F6); 229 F.add(F6); 230 n_f += 1; 231 } 232 if (list.contains(F7)) { 233 pixel = tree_map1.getPixel(0, 0, 255); 234 map.put(F7, pixel); 235 list.remove(F7); 236 F.add(F7); 237 n_f += 1; 238 } 239 if (list.contains(F8)) { 240 pixel = tree_map1.getPixel(0, 0, 255); 241 map.put(F8, pixel); 242 list.remove(F8); 243 F.add(F8); 244 n_f += 1; 245 } 246 if (list.contains(F9)) { 247 pixel = tree_map1.getPixel(0, 0, 255); 248 map.put(F9, pixel); 249 list.remove(F9); 250 F.add(F9); 251 n_f += 1; 252 } 253 } 254 } 255 256 private static void eSpread(int n) { 257 if (n_e < 40876) { 258 int pixel = 0; 259 int Xe = Integer.parseInt((E.get(n).split(","))[0]); 260 int Ye = Integer.parseInt((E.get(n).split(","))[1]); 261 String E1 = (Xe + 1) + "" + "," + Ye + ""; 262 String E2 = Xe + "" + "," + (Ye + 1) + ""; 263 String E3 = (Xe - 1) + "" + "," + Ye + ""; 264 String E4 = Xe + "" + "," + (Ye - 1) + ""; 265 String E5 = (Xe + 1) + "" + "," + (Ye + 1) + ""; 266 String E6 = (Xe + 1) + "" + "," + (Ye - 1) + ""; 267 String E7 = Xe + "" + "," + Ye + ""; 268 String E8 = (Xe - 1) + "" + "," + (Ye - 1) + ""; 269 String E9 = (Xe - 1) + "" + "," + (Ye + 1) + ""; 270 // 資源池包含E點,則進行染色,否則不做處理 271 if (list.contains(E1)) { 272 pixel = tree_map1.getPixel(0, 255, 255); 273 map.put(E1, pixel); 274 list.remove(E1); 275 E.add(E1); 276 n_e += 1; 277 } 278 if (list.contains(E2)) { 279 pixel = tree_map1.getPixel(0, 255, 255); 280 map.put(E2, pixel); 281 list.remove(E2); 282 E.add(E2); 283 n_e += 1; 284 } 285 if (list.contains(E3)) { 286 pixel = tree_map1.getPixel(0, 255, 255); 287 map.put(E3, pixel); 288 list.remove(E3); 289 E.add(E3); 290 n_e += 1; 291 } 292 if (list.contains(E4)) { 293 pixel = tree_map1.getPixel(0, 255, 255); 294 map.put(E4, pixel); 295 list.remove(E4); 296 E.add(E4); 297 n_e += 1; 298 } 299 if (list.contains(E5)) { 300 pixel = tree_map1.getPixel(0, 255, 255); 301 map.put(E5, pixel); 302 list.remove(E5); 303 E.add(E5); 304 n_e += 1; 305 } 306 if (list.contains(E6)) { 307 pixel = tree_map1.getPixel(0, 255, 255); 308 map.put(E6, pixel); 309 list.remove(E6); 310 E.add(E6); 311 n_e += 1; 312 } 313 if (list.contains(E7)) { 314 pixel = tree_map1.getPixel(0, 255, 255); 315 map.put(E7, pixel); 316 list.remove(E7); 317 E.add(E7); 318 n_e += 1; 319 } 320 if (list.contains(E8)) { 321 pixel = tree_map1.getPixel(0, 255, 255); 322 map.put(E8, pixel); 323 list.remove(E8); 324 E.add(E8); 325 n_e += 1; 326 } 327 if (list.contains(E9)) { 328 pixel = tree_map1.getPixel(0, 255, 255); 329 map.put(E9, pixel); 330 list.remove(E9); 331 E.add(E9); 332 n_e += 1; 333 } 334 } 335 } 336 337 private static void dSpread(int n) { 338 if (n_d < 45204) { 339 int pixel = 0; 340 int Xd = Integer.parseInt((D.get(n).split(","))[0]); 341 int Yd = Integer.parseInt((D.get(n).split(","))[1]); 342 String D1 = (Xd + 1) + "" + "," + Yd + ""; 343 String D2 = Xd + "" + "," + (Yd + 1) + ""; 344 String D3 = (Xd - 1) + "" + "," + Yd + ""; 345 String D4 = Xd + "" + "," + (Yd - 1) + ""; 346 String D5 = (Xd + 1) + "" + "," + (Yd + 1) + ""; 347 String D6 = (Xd + 1) + "" + "," + (Yd - 1) + ""; 348 String D7 = Xd + "" + "," + Yd + ""; 349 String D8 = (Xd - 1) + "" + "," + (Yd - 1) + ""; 350 String D9 = (Xd - 1) + "" + "," + (Yd + 1) + ""; 351 // 資源池包含D點,則進行染色,否則不做處理 352 if (list.contains(D1)) { 353 pixel = tree_map1.getPixel(0, 255, 0); 354 map.put(D1, pixel); 355 list.remove(D1); 356 D.add(D1); 357 n_d += 1; 358 } 359 if (list.contains(D2)) { 360 pixel = tree_map1.getPixel(0, 255, 0); 361 map.put(D2, pixel); 362 list.remove(D2); 363 D.add(D2); 364 n_d += 1; 365 } 366 if (list.contains(D3)) { 367 pixel = tree_map1.getPixel(0, 255, 0); 368 map.put(D3, pixel); 369 list.remove(D3); 370 D.add(D3); 371 n_d += 1; 372 } 373 if (list.contains(D4)) { 374 pixel = tree_map1.getPixel(0, 255, 0); 375 map.put(D4, pixel); 376 list.remove(D4); 377 D.add(D4); 378 n_d += 1; 379 } 380 if (list.contains(D5)) { 381 pixel = tree_map1.getPixel(0, 255, 0); 382 map.put(D5, pixel); 383 list.remove(D5); 384 D.add(D5); 385 n_d += 1; 386 } 387 if (list.contains(D6)) { 388 pixel = tree_map1.getPixel(0, 255, 0); 389 map.put(D6, pixel); 390