From 9bb47cb1cf0479d1c4d0d97fe0e43847dffefc40 Mon Sep 17 00:00:00 2001 From: kokeunho Date: Sat, 30 Aug 2025 17:49:10 +0900 Subject: [PATCH] 34-kokeunho --- kokeunho/.DS_Store | Bin 8196 -> 6148 bytes kokeunho/README.md | 1 + .../34-kokeunho.java" | 70 ++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 "kokeunho/\352\265\254\355\230\204/34-kokeunho.java" diff --git a/kokeunho/.DS_Store b/kokeunho/.DS_Store index 1256d342acc38c13a53c72f1cefd877ab570e485..90ac3c76966b3328a6d4a56c4589f8a1119136f6 100644 GIT binary patch delta 174 zcmZp1XfcprU|?W$DortDU=RQ@Ie-{Mvv5r;6q~50$jH4hU^g=(_hcRc6*fj$pv=6< z1p;c5V+8mn-x3v^>@KvD!_?eFN5R;{a59gG{bX}thso1L1SeOB$WQJU^`87fOmOmL zF;O-KN08pl@5Ce-CpOGk%+A3f$P5$#0s(Fy;R>>HW8rt^$^0^&AO|ooK^y~eAH(K& Ho;l0_V? zPv&7!ne4+RIN6a!la1*rP_^D3w=>L^rO8W{lD#%8s(9FwhC4S>c<^W~%)1}Ep| z768oxg2^^43L?4rE-p~xIhOt3GDYj*F~`YvEOJ1J6s!__1sUju@RS7?<>ln(r2`FR zoLs@OhQq|nQb)nq++wm0YdtU9+8^6zTxDTUxNzaX$;nGt8aPZ$fNnD~H2_N6OQJ}l zn6!e`c=BpiL68;^Bajwj6BC5j%uFU*uo}y9to^Zb%~lZxg`+-e9_(Cmat4YKH(329 zXR!!Q=4a!C*lY+4Awv^Okj?Te$0zJKvo_~M0kRgLADB-RT+Q5(Fj<04ese4vAEO{M vD7b)8$PFZ1LD9HbkmEb^WPTCP$^JYX9E^|{W|$n$Gj;M$7VQCaEH@(n1wpqg 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