diff --git a/kokeunho/.DS_Store b/kokeunho/.DS_Store index 1256d34..90ac3c7 100644 Binary files a/kokeunho/.DS_Store and b/kokeunho/.DS_Store differ diff --git a/kokeunho/README.md b/kokeunho/README.md index c4b912d..6883ec8 100644 --- a/kokeunho/README.md +++ b/kokeunho/README.md @@ -32,4 +32,5 @@ | 29차시 | 2025.07.21 | 그래프 탐색 | [불!](https://www.acmicpc.net/problem/4179) |[#118](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/118) | | 30차시 | 2025.07.26 | 그래프 탐색 | [중량제한](https://www.acmicpc.net/problem/1939) |[#120](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/120) | | 31차시 | 2025.08.03 | 그래프 탐색 | [면접보는 승범이네](https://www.acmicpc.net/problem/17835) | [#126](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/126) | +| 34차시 | 2025.08.30 | 구현 | [아날로그 시계](https://school.programmers.co.kr/learn/courses/30/lessons/250135) | [#137](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/137) | --- diff --git "a/kokeunho/\352\265\254\355\230\204/34-kokeunho.java" "b/kokeunho/\352\265\254\355\230\204/34-kokeunho.java" new file mode 100644 index 0000000..156c5bb --- /dev/null +++ "b/kokeunho/\352\265\254\355\230\204/34-kokeunho.java" @@ -0,0 +1,70 @@ +import java.util.*; + +class Solution { + public int solution(int h1, int m1, int s1, int h2, int m2, int s2) { + int answer = 0; + + int start = changeToSec(h1, m1, s1); + int end = changeToSec(h2, m2, s2); + + + for (int i = start; i < end; i++) { + List current = getDegree(i); + List next = getDegree(i+1); + + boolean hMatch = hourMatch(current, next); + boolean mMatch = minMatch(current, next); + + // 초침이 분침과 시침과 겹침이 발생했을 때, + if(hMatch && mMatch){ + // 시침과 분침의 각도가 같다면 +1만 해줘야함 + if(Double.compare(next.get(0),next.get(1)) == 0) answer++; + // 아니라면 +2 + else answer +=2; + } + // 둘 중 하나라도 겹치면 +1 + else if(hMatch || mMatch) answer++; + } + + if(start == 0 || start == 43200) answer++; + + return answer; + } + public int changeToSec(int h, int m, int s) { + return 3600*h + 60*m + s; + } + + public List getDegree(int t) { + int h = t/3600; + int m = (t%3600) / 60; + int s = (t%3600) % 60; + + Double hDegree = (h%12) * 30 + m*0.5 + s*(1.0/120); + Double mDegree = m*6 + s*(0.1); + Double sDegree = s*6.0; + + return List.of(hDegree, mDegree, sDegree); + } + public boolean hourMatch(List current, List next) { + if (Double.compare(current.get(0), current.get(2)) > 0 + && Double.compare(next.get(0), next.get(2)) <= 0) { + return true; + } + if (Double.compare(current.get(2), 354) == 0 + && Double.compare(current.get(0), 354) > 0) { + return true; + } + return false; + } + public boolean minMatch(List current, List next) { + if (Double.compare(current.get(1), current.get(2)) > 0 + && Double.compare(next.get(1), next.get(2)) <= 0) { + return true; + } + if (Double.compare(current.get(2), 354) == 0 + && Double.compare(current.get(1), 354) > 0) { + return true; + } + return false; + } +} \ No newline at end of file