From 1874b84be3119aec8173118a97637ef64d07efa0 Mon Sep 17 00:00:00 2001 From: isobe Date: Fri, 4 Jul 2025 17:15:08 +0900 Subject: [PATCH 1/4] =?UTF-8?q?paizaB165=E3=81=AE=E5=9B=9E=E7=AD=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tisobe/src/B165.java | 87 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 tisobe/src/B165.java diff --git a/tisobe/src/B165.java b/tisobe/src/B165.java new file mode 100644 index 0000000..2f776d9 --- /dev/null +++ b/tisobe/src/B165.java @@ -0,0 +1,87 @@ +package tisobe.src; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Scanner; + +public class B165 { + public static void main(String[] args) { + // 自分の得意な言語で + // Let's チャレンジ!! + final Scanner sc = new Scanner(System.in); + + final int MAP_HEIGHT = sc.nextInt(); + final int MAP_WIDTH = sc.nextInt(); + final int FIRE_LOCATE_X = sc.nextInt(); + final int FIRE_LOCATE_Y = sc.nextInt(); + final int TIME = sc.nextInt(); + + StringBuilder forestMap = new StringBuilder(); + + // 森林の作成 + final List> FOREST = new ArrayList<>(); + for (int i = 0; i < MAP_HEIGHT; i++) { + FOREST.add(Arrays.asList(sc.next().split(""))); + } + // 初期火災の発生 + FOREST.get(FIRE_LOCATE_X - 1).set(FIRE_LOCATE_Y - 1, "B"); + + //森林火災のシミュレーション + for (int t = 0; t < TIME; t++) { + for (int y = 0; y < MAP_HEIGHT; y++) { + for (int x = 0; x < MAP_WIDTH; x++) { + spred_Fire_Tree(FOREST, y, x, MAP_HEIGHT, MAP_WIDTH); + } + } + //燃えている箇所の確定 + for (int y = 0; y < MAP_HEIGHT; y++) { + Collections.replaceAll(FOREST.get(y), "Burning", "B"); + } + } + + //結果の作成 + for (int y = 0; y < MAP_HEIGHT; y++) { + for (int x = 0; x < MAP_WIDTH; x++) { + forestMap.append(FOREST.get(y).get(x)); + } + forestMap.append("\n"); + } + System.out.println(forestMap); + sc.close(); + } + +/**木("#")を燃やす + * TIMEに応じて炎の判定をおこなうため"Burning"で仮置き*/ + public static void burning_Tree(final List> FOREST, final int Y, final int X) { + if (FOREST.get(Y).get(X).equals("#")) { + FOREST.get(Y).set(X, "Burning"); + } + } + +/**隣接するマスに炎を広げて、燃えている箇所を灰にする*/ + public static void spred_Fire_Tree(final List> FOREST, final int Y, final int X, + final int MAP_HEIGHT, final int MAP_WIDTH) { + if (FOREST.get(Y).get(X).equals("B")) { + + // 左に延焼 + if (X - 1 >= 0) { + burning_Tree(FOREST, Y, X - 1); + } + // 上に延焼 + if (Y - 1 >= 0) { + burning_Tree(FOREST, Y - 1, X); + } + // 右に延焼 + if (X + 1 < MAP_WIDTH - 1) { + burning_Tree(FOREST, Y, X + 1); + } + // 下に延焼 + if (Y + 1 < MAP_HEIGHT - 1) { + burning_Tree(FOREST, Y + 1, X); + } + FOREST.get(Y).set(X, "A"); + } + } +} -- GitLab From 360db86eee827a40d5c4e5e9e69722d4b9f2e03a Mon Sep 17 00:00:00 2001 From: isobe Date: Mon, 7 Jul 2025 14:55:34 +0900 Subject: [PATCH 2/4] =?UTF-8?q?paiza=E3=81=AE=E5=95=8F=E9=A1=8CB165?= =?UTF-8?q?=E3=81=AE=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tisobe/src/B165.java | 82 +++++++++++++++++++++++++++++++------------- 1 file changed, 58 insertions(+), 24 deletions(-) diff --git a/tisobe/src/B165.java b/tisobe/src/B165.java index 2f776d9..b2f9293 100644 --- a/tisobe/src/B165.java +++ b/tisobe/src/B165.java @@ -6,7 +6,27 @@ import java.util.Collections; import java.util.List; import java.util.Scanner; +enum Fire_situation { + TREE("#"), + TREELESS("."), + BURNED("B"), + BURING("Burning"), + ASH("A"); + + private String symbolOfMap; + + private Fire_situation(String symbolOfMap) { + this.symbolOfMap = symbolOfMap; + } + + public String getSymbol() { + return symbolOfMap; + } +} + + public class B165 { + public static void main(String[] args) { // 自分の得意な言語で // Let's チャレンジ!! @@ -17,7 +37,7 @@ public class B165 { final int FIRE_LOCATE_X = sc.nextInt(); final int FIRE_LOCATE_Y = sc.nextInt(); final int TIME = sc.nextInt(); - + StringBuilder forestMap = new StringBuilder(); // 森林の作成 @@ -25,23 +45,14 @@ public class B165 { for (int i = 0; i < MAP_HEIGHT; i++) { FOREST.add(Arrays.asList(sc.next().split(""))); } - // 初期火災の発生 - FOREST.get(FIRE_LOCATE_X - 1).set(FIRE_LOCATE_Y - 1, "B"); + Forest Forest = new Forest(FIRE_LOCATE_X, FIRE_LOCATE_Y, FOREST); - //森林火災のシミュレーション + // 森林火災のシミュレーション for (int t = 0; t < TIME; t++) { - for (int y = 0; y < MAP_HEIGHT; y++) { - for (int x = 0; x < MAP_WIDTH; x++) { - spred_Fire_Tree(FOREST, y, x, MAP_HEIGHT, MAP_WIDTH); - } - } - //燃えている箇所の確定 - for (int y = 0; y < MAP_HEIGHT; y++) { - Collections.replaceAll(FOREST.get(y), "Burning", "B"); - } + Forest.simulation_Fire(MAP_HEIGHT, MAP_WIDTH, FOREST); } - - //結果の作成 + + // 結果の作成 for (int y = 0; y < MAP_HEIGHT; y++) { for (int x = 0; x < MAP_WIDTH; x++) { forestMap.append(FOREST.get(y).get(x)); @@ -51,19 +62,42 @@ public class B165 { System.out.println(forestMap); sc.close(); } - -/**木("#")を燃やす - * TIMEに応じて炎の判定をおこなうため"Burning"で仮置き*/ + +} + + +class Forest { + public Forest(int FIRE_LOCATE_X, int FIRE_LOCATE_Y, List> FOREST) { + FOREST.get(FIRE_LOCATE_X - 1).set(FIRE_LOCATE_Y - 1, Fire_situation.BURNED.getSymbol()); + } + + public void simulation_Fire(int MAP_HEIGHT, int MAP_WIDTH, List> FOREST) { + for (int y = 0; y < MAP_HEIGHT; y++) { + for (int x = 0; x < MAP_WIDTH; x++) { + Forest.spred_Fire_Tree(FOREST, y, x, MAP_HEIGHT, MAP_WIDTH); + } + } + // 燃えている箇所の確定 + for (int y = 0; y < MAP_HEIGHT; y++) { + Collections + .replaceAll(FOREST.get(y), Fire_situation.BURING.getSymbol(), Fire_situation.BURNED + .getSymbol()); + } + } + + /** + * 木("#")を燃やす TIMEに応じて炎の判定をおこなうため"Burning"で仮置き + */ public static void burning_Tree(final List> FOREST, final int Y, final int X) { - if (FOREST.get(Y).get(X).equals("#")) { - FOREST.get(Y).set(X, "Burning"); + if (FOREST.get(Y).get(X).equals(Fire_situation.TREE.getSymbol())) { + FOREST.get(Y).set(X, Fire_situation.BURING.getSymbol()); } } - -/**隣接するマスに炎を広げて、燃えている箇所を灰にする*/ + + /** 隣接するマスに炎を広げて、燃えている箇所を灰にする */ public static void spred_Fire_Tree(final List> FOREST, final int Y, final int X, final int MAP_HEIGHT, final int MAP_WIDTH) { - if (FOREST.get(Y).get(X).equals("B")) { + if (FOREST.get(Y).get(X).equals(Fire_situation.BURNED.getSymbol())) { // 左に延焼 if (X - 1 >= 0) { @@ -81,7 +115,7 @@ public class B165 { if (Y + 1 < MAP_HEIGHT - 1) { burning_Tree(FOREST, Y + 1, X); } - FOREST.get(Y).set(X, "A"); + FOREST.get(Y).set(X, Fire_situation.ASH.getSymbol()); } } } -- GitLab From e6d7984f265e466a44f265f8b8c99da32e60664f Mon Sep 17 00:00:00 2001 From: isobe Date: Tue, 8 Jul 2025 15:56:51 +0900 Subject: [PATCH 3/4] =?UTF-8?q?paiza=E3=81=AEB165=E3=81=AE=E4=BF=AE?= =?UTF-8?q?=E6=AD=A32=E5=9B=9E=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tisobe/src/B165.java | 80 +++++++++++++++++++++++++++----------------- 1 file changed, 49 insertions(+), 31 deletions(-) diff --git a/tisobe/src/B165.java b/tisobe/src/B165.java index b2f9293..7217131 100644 --- a/tisobe/src/B165.java +++ b/tisobe/src/B165.java @@ -32,11 +32,11 @@ public class B165 { // Let's チャレンジ!! final Scanner sc = new Scanner(System.in); - final int MAP_HEIGHT = sc.nextInt(); - final int MAP_WIDTH = sc.nextInt(); + final int MAP_HEIGHT = sc.nextInt(); + final int MAP_WIDTH = sc.nextInt(); final int FIRE_LOCATE_X = sc.nextInt(); final int FIRE_LOCATE_Y = sc.nextInt(); - final int TIME = sc.nextInt(); + final int TIME = sc.nextInt(); StringBuilder forestMap = new StringBuilder(); @@ -45,17 +45,13 @@ public class B165 { for (int i = 0; i < MAP_HEIGHT; i++) { FOREST.add(Arrays.asList(sc.next().split(""))); } - Forest Forest = new Forest(FIRE_LOCATE_X, FIRE_LOCATE_Y, FOREST); - - // 森林火災のシミュレーション - for (int t = 0; t < TIME; t++) { - Forest.simulation_Fire(MAP_HEIGHT, MAP_WIDTH, FOREST); - } + Forest Forest = new Forest(MAP_HEIGHT, MAP_WIDTH, FIRE_LOCATE_X, FIRE_LOCATE_Y, TIME, FOREST); // 結果の作成 + Forest.setFOREST(); for (int y = 0; y < MAP_HEIGHT; y++) { for (int x = 0; x < MAP_WIDTH; x++) { - forestMap.append(FOREST.get(y).get(x)); + forestMap.append(Forest.getFOREST().get(y).get(x)); } forestMap.append("\n"); } @@ -67,53 +63,75 @@ public class B165 { class Forest { - public Forest(int FIRE_LOCATE_X, int FIRE_LOCATE_Y, List> FOREST) { - FOREST.get(FIRE_LOCATE_X - 1).set(FIRE_LOCATE_Y - 1, Fire_situation.BURNED.getSymbol()); + private final int MAP_HEIGHT; + private final int MAP_WIDTH; + private final int FIRE_LOCATE_X; + private final int FIRE_LOCATE_Y; + private final int TIME; + private final List> FOREST; + + public Forest(final int MAP_HEIGHT, final int MAP_WIDTH, final int FIRE_LOCATE_X, + final int FIRE_LOCATE_Y, final int TIME, final List> FOREST) { + this.FIRE_LOCATE_X = FIRE_LOCATE_X; + this.FIRE_LOCATE_Y = FIRE_LOCATE_Y; + this.MAP_HEIGHT = MAP_HEIGHT; + this.MAP_WIDTH = MAP_WIDTH; + this.TIME = TIME; + this.FOREST = FOREST; + this.FOREST.get(FIRE_LOCATE_X - 1).set(FIRE_LOCATE_Y - 1, Fire_situation.BURNED.getSymbol()); } - public void simulation_Fire(int MAP_HEIGHT, int MAP_WIDTH, List> FOREST) { - for (int y = 0; y < MAP_HEIGHT; y++) { - for (int x = 0; x < MAP_WIDTH; x++) { - Forest.spred_Fire_Tree(FOREST, y, x, MAP_HEIGHT, MAP_WIDTH); + public List> getFOREST() { + return FOREST; + } + public void setFOREST() { + simulation_Fire(); + } + + public void simulation_Fire() { + for (int t = 0; t < TIME; t++) { + for (int y = 0; y < MAP_HEIGHT; y++) { + for (int x = 0; x < MAP_WIDTH; x++) { + spred_Fire_Tree(y, x); + } + } + // 燃えている箇所の確定 + for (int y = 0; y < MAP_HEIGHT; y++) { + Collections + .replaceAll(FOREST.get(y), Fire_situation.BURING.getSymbol(), Fire_situation.BURNED + .getSymbol()); } - } - // 燃えている箇所の確定 - for (int y = 0; y < MAP_HEIGHT; y++) { - Collections - .replaceAll(FOREST.get(y), Fire_situation.BURING.getSymbol(), Fire_situation.BURNED - .getSymbol()); } } /** * 木("#")を燃やす TIMEに応じて炎の判定をおこなうため"Burning"で仮置き */ - public static void burning_Tree(final List> FOREST, final int Y, final int X) { + public void burning_Tree(final int Y, final int X) { if (FOREST.get(Y).get(X).equals(Fire_situation.TREE.getSymbol())) { FOREST.get(Y).set(X, Fire_situation.BURING.getSymbol()); } } /** 隣接するマスに炎を広げて、燃えている箇所を灰にする */ - public static void spred_Fire_Tree(final List> FOREST, final int Y, final int X, - final int MAP_HEIGHT, final int MAP_WIDTH) { + public void spred_Fire_Tree(final int Y, final int X) { if (FOREST.get(Y).get(X).equals(Fire_situation.BURNED.getSymbol())) { // 左に延焼 if (X - 1 >= 0) { - burning_Tree(FOREST, Y, X - 1); + burning_Tree(Y, X - 1); } // 上に延焼 if (Y - 1 >= 0) { - burning_Tree(FOREST, Y - 1, X); + burning_Tree(Y - 1, X); } // 右に延焼 - if (X + 1 < MAP_WIDTH - 1) { - burning_Tree(FOREST, Y, X + 1); + if (X + 1 < MAP_WIDTH) { + burning_Tree(Y, X + 1); } // 下に延焼 - if (Y + 1 < MAP_HEIGHT - 1) { - burning_Tree(FOREST, Y + 1, X); + if (Y + 1 < MAP_HEIGHT) { + burning_Tree(Y + 1, X); } FOREST.get(Y).set(X, Fire_situation.ASH.getSymbol()); } -- GitLab From 09852b7a5260683f699cc1968eff3908e164e2b9 Mon Sep 17 00:00:00 2001 From: isobe Date: Wed, 9 Jul 2025 09:52:16 +0900 Subject: [PATCH 4/4] =?UTF-8?q?paiza=E3=81=AE=E5=95=8F=E9=A1=8CB165?= =?UTF-8?q?=E3=81=AE3=E5=9B=9E=E7=9B=AE=E3=81=AE=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tisobe/src/B165.java | 105 +++++++++++++++++++++---------------------- 1 file changed, 52 insertions(+), 53 deletions(-) diff --git a/tisobe/src/B165.java b/tisobe/src/B165.java index 7217131..d0a5d11 100644 --- a/tisobe/src/B165.java +++ b/tisobe/src/B165.java @@ -38,24 +38,18 @@ public class B165 { final int FIRE_LOCATE_Y = sc.nextInt(); final int TIME = sc.nextInt(); - StringBuilder forestMap = new StringBuilder(); - - // 森林の作成 final List> FOREST = new ArrayList<>(); for (int i = 0; i < MAP_HEIGHT; i++) { FOREST.add(Arrays.asList(sc.next().split(""))); } - Forest Forest = new Forest(MAP_HEIGHT, MAP_WIDTH, FIRE_LOCATE_X, FIRE_LOCATE_Y, TIME, FOREST); - // 結果の作成 - Forest.setFOREST(); - for (int y = 0; y < MAP_HEIGHT; y++) { - for (int x = 0; x < MAP_WIDTH; x++) { - forestMap.append(Forest.getFOREST().get(y).get(x)); - } - forestMap.append("\n"); + Forest Forest = new Forest(MAP_HEIGHT, MAP_WIDTH, FIRE_LOCATE_X, FIRE_LOCATE_Y, FOREST); + for (int t = 0; t < TIME; t++) { + Forest.simulation_Fire(); } - System.out.println(forestMap); + + + System.out.println(Forest.makeForestMap()); sc.close(); } @@ -63,77 +57,82 @@ public class B165 { class Forest { - private final int MAP_HEIGHT; - private final int MAP_WIDTH; - private final int FIRE_LOCATE_X; - private final int FIRE_LOCATE_Y; - private final int TIME; - private final List> FOREST; + private int map_Height; + private int map_Width; + private int fire_Locate_X; + private int fire_Locate_Y; + private List> forest; public Forest(final int MAP_HEIGHT, final int MAP_WIDTH, final int FIRE_LOCATE_X, - final int FIRE_LOCATE_Y, final int TIME, final List> FOREST) { - this.FIRE_LOCATE_X = FIRE_LOCATE_X; - this.FIRE_LOCATE_Y = FIRE_LOCATE_Y; - this.MAP_HEIGHT = MAP_HEIGHT; - this.MAP_WIDTH = MAP_WIDTH; - this.TIME = TIME; - this.FOREST = FOREST; - this.FOREST.get(FIRE_LOCATE_X - 1).set(FIRE_LOCATE_Y - 1, Fire_situation.BURNED.getSymbol()); + final int FIRE_LOCATE_Y, List> FOREST) { + this.fire_Locate_X = FIRE_LOCATE_X; + this.fire_Locate_Y = FIRE_LOCATE_Y; + this.map_Height = MAP_HEIGHT; + this.map_Width = MAP_WIDTH; + this.forest = FOREST; + this.forest.get(FIRE_LOCATE_X - 1).set(FIRE_LOCATE_Y - 1, Fire_situation.BURNED.getSymbol()); } public List> getFOREST() { - return FOREST; - } - public void setFOREST() { - simulation_Fire(); + return forest; } public void simulation_Fire() { - for (int t = 0; t < TIME; t++) { - for (int y = 0; y < MAP_HEIGHT; y++) { - for (int x = 0; x < MAP_WIDTH; x++) { - spred_Fire_Tree(y, x); - } - } - // 燃えている箇所の確定 - for (int y = 0; y < MAP_HEIGHT; y++) { - Collections - .replaceAll(FOREST.get(y), Fire_situation.BURING.getSymbol(), Fire_situation.BURNED - .getSymbol()); + for (int y = 0; y < map_Height; y++) { + for (int x = 0; x < map_Width; x++) { + spredFireTree(y, x); } } + // 燃えている箇所の確定 + for (int y = 0; y < map_Height; y++) { + Collections + .replaceAll(forest.get(y), Fire_situation.BURING.getSymbol(), Fire_situation.BURNED + .getSymbol()); + } } /** * 木("#")を燃やす TIMEに応じて炎の判定をおこなうため"Burning"で仮置き */ - public void burning_Tree(final int Y, final int X) { - if (FOREST.get(Y).get(X).equals(Fire_situation.TREE.getSymbol())) { - FOREST.get(Y).set(X, Fire_situation.BURING.getSymbol()); + public void burningTree(final int Y, final int X) { + if (forest.get(Y).get(X).equals(Fire_situation.TREE.getSymbol())) { + forest.get(Y).set(X, Fire_situation.BURING.getSymbol()); } } /** 隣接するマスに炎を広げて、燃えている箇所を灰にする */ - public void spred_Fire_Tree(final int Y, final int X) { - if (FOREST.get(Y).get(X).equals(Fire_situation.BURNED.getSymbol())) { + public void spredFireTree(final int Y, final int X) { + if (forest.get(Y).get(X).equals(Fire_situation.BURNED.getSymbol())) { // 左に延焼 if (X - 1 >= 0) { - burning_Tree(Y, X - 1); + burningTree(Y, X - 1); } // 上に延焼 if (Y - 1 >= 0) { - burning_Tree(Y - 1, X); + burningTree(Y - 1, X); } // 右に延焼 - if (X + 1 < MAP_WIDTH) { - burning_Tree(Y, X + 1); + if (X + 1 < map_Width) { + burningTree(Y, X + 1); } // 下に延焼 - if (Y + 1 < MAP_HEIGHT) { - burning_Tree(Y + 1, X); + if (Y + 1 < map_Height) { + burningTree(Y + 1, X); } - FOREST.get(Y).set(X, Fire_situation.ASH.getSymbol()); + forest.get(Y).set(X, Fire_situation.ASH.getSymbol()); + } + } + + public String makeForestMap() { + // 結果の作成 + StringBuilder forestMap = new StringBuilder(); + for (int y = 0; y < map_Height; y++) { + for (int x = 0; x < map_Width; x++) { + forestMap.append(forest.get(y).get(x)); + } + forestMap.append("\n"); } + return forestMap.toString(); } } -- GitLab