From 0996c04e3154f5ebd3e09e442c3b022373e4d9b9 Mon Sep 17 00:00:00 2001 From: aiken516 Date: Mon, 11 Aug 2025 10:26:33 +0900 Subject: [PATCH] =?UTF-8?q?[=EB=85=B8=ED=98=95=EB=AF=BC]=20Day11?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Q3633.cs" | 50 +++++++++++++++++++ .../Q808.cs" | 50 +++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 "leetcode2/1easy/\353\205\270\355\230\225\353\257\274/Q3633.cs" create mode 100644 "leetcode2/2medium/\353\205\270\355\230\225\353\257\274/Q808.cs" diff --git "a/leetcode2/1easy/\353\205\270\355\230\225\353\257\274/Q3633.cs" "b/leetcode2/1easy/\353\205\270\355\230\225\353\257\274/Q3633.cs" new file mode 100644 index 00000000..0dc998fe --- /dev/null +++ "b/leetcode2/1easy/\353\205\270\355\230\225\353\257\274/Q3633.cs" @@ -0,0 +1,50 @@ +public class Solution +{ + public int EarliestFinishTime(int[] landStartTime, int[] landDuration, int[] waterStartTime, int[] waterDuration) + { + int minTime = 10000; + for (int i = 0; i < landStartTime.Length; i++) + { + for (int j = 0; j < waterStartTime.Length; j++) + { + int currentTime = landStartTime[i] + landDuration[i]; + if (waterStartTime[j] <= currentTime) + { + currentTime += waterDuration[j]; + } + else + { + currentTime = waterStartTime[j] + waterDuration[j]; + } + + if (currentTime < minTime) + { + minTime = currentTime; + } + } + } + + for (int i = 0; i < waterStartTime.Length; i++) + { + for (int j = 0; j < landStartTime.Length; j++) + { + int currentTime = waterStartTime[i] + waterDuration[i]; + if (landStartTime[j] <= currentTime) + { + currentTime += landDuration[j]; + } + else + { + currentTime = landStartTime[j] + landDuration[j]; + } + + if (currentTime < minTime) + { + minTime = currentTime; + } + } + } + + return minTime; + } +} \ No newline at end of file diff --git "a/leetcode2/2medium/\353\205\270\355\230\225\353\257\274/Q808.cs" "b/leetcode2/2medium/\353\205\270\355\230\225\353\257\274/Q808.cs" new file mode 100644 index 00000000..74dd0f0f --- /dev/null +++ "b/leetcode2/2medium/\353\205\270\355\230\225\353\257\274/Q808.cs" @@ -0,0 +1,50 @@ +public class Solution +{ + double?[,] possibility; + + public double SoupServings(int n) + { + n = (n+24) / 25; + + if (n > 4800) + { + return 1.0; + } + + possibility = new double?[n + 1, n + 1]; + + return GetPossibility(n, n); + } + + private double GetPossibility(int i, int j) + { + if (i <= 0 && j <= 0) + { + return 0.5; + } + if (i <= 0) + { + return 1.0; + } + if (j <= 0) + { + return 0.0; + } + + if (possibility[i, j] != null) + { + return possibility[i, j].Value; + } + + double result = 0.25 * ( + GetPossibility(i - 4, j) + + GetPossibility(i - 3, j - 1) + + GetPossibility(i - 2, j - 2) + + GetPossibility(i - 1, j - 3) + ); + + possibility[i, j] = result; + + return result; + } +} \ No newline at end of file