From 89a82ea46f872e0e79517f7783944a793d982015 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BC=8A=E8=97=A4=20=E8=81=96=E5=A4=9C?= Date: Fri, 5 Jul 2024 16:17:02 +0900 Subject: [PATCH 1/4] =?UTF-8?q?paiza=E3=81=AEB146=E3=81=AE=E5=9B=9E?= =?UTF-8?q?=E7=AD=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sitou/src/B146_battle.java | 57 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 sitou/src/B146_battle.java diff --git a/sitou/src/B146_battle.java b/sitou/src/B146_battle.java new file mode 100644 index 0000000..fc70c40 --- /dev/null +++ b/sitou/src/B146_battle.java @@ -0,0 +1,57 @@ +package src; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Scanner; + +public class B146_battle { + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int singleAttack = sc.nextInt(); + int allAttack = sc.nextInt(); + int monsters = sc.nextInt(); + ArrayList monstersHPList = new ArrayList<>(); + + for(int i = 0; i < monsters; i++) { + monstersHPList.add(sc.nextInt()); + } + + int count = AttackCount(monstersHPList,allAttack,singleAttack); + System.out.println(count); + sc.close(); + } + + + static int AttackCount(ArrayList monstersHPList, int allAttack, int singleAttack) { + int count = 0; + + while(monstersHPList.size() > 0) { + Collections.sort(monstersHPList, Collections.reverseOrder()); + + int allOnlyCount = 0; + int singleOnlyCount = 0; + + allOnlyCount = (int) Math.ceil(monstersHPList.get(0)/allAttack); + for(int n=0;n hp - allAttack); + }else { + //最大HPの敵に単体攻撃 + monstersHPList.set(0, monstersHPList.get(0) - singleAttack); + } + + count++; + //敵がいなくなるまで続けるため + monstersHPList.removeIf(hp -> hp <= 0); + } + + return count; + } + +} -- GitLab From e2a2ae1edb4459d74a70059c9c6f07c0460d51f3 Mon Sep 17 00:00:00 2001 From: sitou Date: Mon, 8 Jul 2024 06:30:17 +0000 Subject: [PATCH 2/4] =?UTF-8?q?B146=E3=81=AE=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sitou/src/B146_battle.java | 55 +++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/sitou/src/B146_battle.java b/sitou/src/B146_battle.java index fc70c40..49ba3a9 100644 --- a/sitou/src/B146_battle.java +++ b/sitou/src/B146_battle.java @@ -8,49 +8,48 @@ public class B146_battle { public static void main(String[] args) { Scanner sc = new Scanner(System.in); - int singleAttack = sc.nextInt(); - int allAttack = sc.nextInt(); - int monsters = sc.nextInt(); + final int singleAttack = sc.nextInt(); + final int allAttack = sc.nextInt(); + final int monsters = sc.nextInt(); ArrayList monstersHPList = new ArrayList<>(); - - for(int i = 0; i < monsters; i++) { + + for (int i = 0; i < monsters; i++) { monstersHPList.add(sc.nextInt()); } - int count = AttackCount(monstersHPList,allAttack,singleAttack); + int count = attackCount(monstersHPList, allAttack, singleAttack); System.out.println(count); sc.close(); } - - - static int AttackCount(ArrayList monstersHPList, int allAttack, int singleAttack) { + + static int attackCount(ArrayList monstersHPList, final int allAttack, + final int singleAttack) { int count = 0; - - while(monstersHPList.size() > 0) { - Collections.sort(monstersHPList, Collections.reverseOrder()); - - int allOnlyCount = 0; + + while (monstersHPList.size() > 0) { + int maxHP = monstersHPList.indexOf(Collections.max(monstersHPList)); + int allOnlyCount = (int) Math.ceil(monstersHPList.get(0) / allAttack); int singleOnlyCount = 0; - - allOnlyCount = (int) Math.ceil(monstersHPList.get(0)/allAttack); - for(int n=0;n hp - allAttack); - }else { - //最大HPの敵に単体攻撃 - monstersHPList.set(0, monstersHPList.get(0) - singleAttack); + } else { + // 最大HPの敵に単体攻撃 + monstersHPList.set(maxHP, maxHP - singleAttack); } - + count++; - //敵がいなくなるまで続けるため + // 敵がいなくなるまで続けるため monstersHPList.removeIf(hp -> hp <= 0); } - + return count; } -- GitLab From 499d8ec88212200c3576f011c4261ab8d6172f33 Mon Sep 17 00:00:00 2001 From: sitou Date: Mon, 8 Jul 2024 08:00:47 +0000 Subject: [PATCH 3/4] Update B146_battle.java --- sitou/src/B146_battle.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/sitou/src/B146_battle.java b/sitou/src/B146_battle.java index 49ba3a9..4358502 100644 --- a/sitou/src/B146_battle.java +++ b/sitou/src/B146_battle.java @@ -4,7 +4,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Scanner; -public class B146_battle { +public class B147_slime { public static void main(String[] args) { Scanner sc = new Scanner(System.in); @@ -22,13 +22,14 @@ public class B146_battle { sc.close(); } - static int attackCount(ArrayList monstersHPList, final int allAttack, - final int singleAttack) { + static int attackCount(ArrayList monstersHPList, int allAttack, + int singleAttack) { int count = 0; while (monstersHPList.size() > 0) { - int maxHP = monstersHPList.indexOf(Collections.max(monstersHPList)); - int allOnlyCount = (int) Math.ceil(monstersHPList.get(0) / allAttack); + final int maxHP = Collections.max(monstersHPList); + final int maxHPIndex = monstersHPList.indexOf(maxHP); + int allOnlyCount = (int) Math.ceil(maxHP / allAttack); int singleOnlyCount = 0; for (int monsterNo : monstersHPList) { @@ -42,7 +43,7 @@ public class B146_battle { monstersHPList.replaceAll(hp -> hp - allAttack); } else { // 最大HPの敵に単体攻撃 - monstersHPList.set(maxHP, maxHP - singleAttack); + monstersHPList.set(maxHPIndex, maxHP - singleAttack); } count++; -- GitLab From ad510cc7e6ddb2e2c0a44acec87fff30f73a5450 Mon Sep 17 00:00:00 2001 From: sitou Date: Mon, 8 Jul 2024 08:06:07 +0000 Subject: [PATCH 4/4] =?UTF-8?q?B146=E3=81=AE=E4=BF=AE=E6=AD=A3=E2=91=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -- GitLab