diff --git "a/minjeong/BruteForce/2025-07-09-[\354\212\244\355\202\254\354\262\264\355\201\254]-[PGS]-#\354\271\264\355\216\253.py" "b/minjeong/BruteForce/2025-07-09-[\354\212\244\355\202\254\354\262\264\355\201\254]-[PGS]-#\354\271\264\355\216\253.py" new file mode 100644 index 00000000..a8f8aa24 --- /dev/null +++ "b/minjeong/BruteForce/2025-07-09-[\354\212\244\355\202\254\354\262\264\355\201\254]-[PGS]-#\354\271\264\355\216\253.py" @@ -0,0 +1,9 @@ +def solution(brown, yellow): + carpet_size = brown + yellow # 카펫의 전체 크기 + + for w in range(1,int(carpet_size**0.5)+1): # 약수 범위 설정. 여기서 w는 너비를 의미함 + if carpet_size % w == 0: # 약수라면 + h = carpet_size // w # 전체 크기에서 너비로 나눈 값을 높이로 설정 + + if (2*w + 2*h - 4 == brown) and ((w-2)*(h-2) == yellow): # 조건에 해당하는지 확인 + return [max(w, h), min(w, h)] diff --git "a/minjeong/Greedy/2025-07-12-[PGS]-\354\240\220\355\224\204\354\231\200\354\210\234\352\260\204\354\235\264\353\217\231.py" "b/minjeong/Greedy/2025-07-12-[PGS]-\354\240\220\355\224\204\354\231\200\354\210\234\352\260\204\354\235\264\353\217\231.py" new file mode 100644 index 00000000..5603706a --- /dev/null +++ "b/minjeong/Greedy/2025-07-12-[PGS]-\354\240\220\355\224\204\354\231\200\354\210\234\352\260\204\354\235\264\353\217\231.py" @@ -0,0 +1,25 @@ +""" +풀이1 +""" +def solution(n): + """ + 이동방법 + 1. K칸 앞으로 점프 => 건전지 사용량 -K + 2. 순간이동: (현재까지 온 거리) * 2 => 건전지 사용량 X + 목표 + - 거리가 N만큼 떨어져있는 장소로 간다고 했을 때 건전지 사용량의 최솟값을 구하기 + """ + ans = 0 + while n > 0: + if (n % 2 == 0): + n //= 2 + else: + n -= 1 + ans += 1 + return ans + +""" +풀이2 +""" +def solution(n): + return bin(n).count('1') \ No newline at end of file diff --git "a/minjeong/Simulation/2025-07-11-[PGS]-\353\202\264\353\247\210\354\235\214\353\214\200\353\241\234\353\254\270\354\236\220\354\227\264\354\240\225\353\240\254\355\225\230\352\270\260(java).java" "b/minjeong/Simulation/2025-07-11-[PGS]-\353\202\264\353\247\210\354\235\214\353\214\200\353\241\234\353\254\270\354\236\220\354\227\264\354\240\225\353\240\254\355\225\230\352\270\260(java).java" new file mode 100644 index 00000000..3e11aae9 --- /dev/null +++ "b/minjeong/Simulation/2025-07-11-[PGS]-\353\202\264\353\247\210\354\235\214\353\214\200\353\241\234\353\254\270\354\236\220\354\227\264\354\240\225\353\240\254\355\225\230\352\270\260(java).java" @@ -0,0 +1,25 @@ +import java.util.*; + +/* +1. n번쨰 글자를 기준으로 오름차순 정렬. +2. 만약 같은 경우 사전순으로 앞선 문자열이 앞으로 와야 한다. +풀이 시간: 30분 +*/ +class Solution { + public String[] solution(String[] strings, int n) { + // n번쨰 기준으로 정렬하기 전에 전체 정렬 + Arrays.sort(strings); + + // n번째 글자를 기준으로 오름차순 정렬 + Arrays.sort(strings, new Comparator() { + @Override + public int compare(String s1, String s2) { + int index = n; + char c1 = s1.charAt(index); + char c2 = s2.charAt(index); + return Character.compare(c1, c2); + } + }); + return strings; + } +} \ No newline at end of file diff --git "a/minjeong/Simulation/2025-07-12-[PGS]-\353\211\264\354\212\244\355\201\264\353\237\254\354\212\244\355\204\260\353\247\201.py" "b/minjeong/Simulation/2025-07-12-[PGS]-\353\211\264\354\212\244\355\201\264\353\237\254\354\212\244\355\204\260\353\247\201.py" new file mode 100644 index 00000000..68a9105f --- /dev/null +++ "b/minjeong/Simulation/2025-07-12-[PGS]-\353\211\264\354\212\244\355\201\264\353\237\254\354\212\244\355\204\260\353\247\201.py" @@ -0,0 +1,52 @@ +def solution(str1, str2): + """ + 1. 다중집합 만들기 + - 문자열을 2글자씩 끊기 + - 두 글자가 모두 알파벳일 때에만 저장하기 (`isalpha()` 이용) + - 대소문자 구분이 없으므로 모두 대문자 또는 소문자 둘 중 하나로 통일하기 (`upper()` or `lower()` 이용) + 2. 다중집합 간의 교집합과 합집합 구하기 + - 다중집합은 중복된 원소를 포함할 수 있다. 따라서 `remove()`를 이용해서 하나씩 비교하며 처리한다. + - 교집합: A 집합과 B 집합의 공통된 원소를 제거해가면서 교집합을 저장할 리스트(`intersect`)에 저장한다 + - 합집합: A의 차집합(A - B) + B의 차집합(B - A) + 교집합으로 구성한다. + 3. 자카드 유사도 구하기 + - 합집합이 공집합일 경우(=합집합 리스트 길이가 0), 유사도는 1로 처리한다. + - 그게 아닐 경우, `교집합 / 합집합` + 4. 정답 반환 + - `자카드 유사도 * 65536` 의 정수 부분을 반환한다. + """ + # 1. 다중집합 만들기 + a = [] + for i in range(len(str1) - 1): + if str1[i:i + 2].isalpha(): + a.append(str1[i:i + 2].upper()) + + b = [] + for i in range(len(str2) - 1): + if str2[i:i + 2].isalpha(): + b.append(str2[i:i + 2].upper()) + + # 2.1. 다중합집합 구하기 + union_set = a.copy() + a_minus_b = a.copy() # A의 차집합 + + for i in b: + if i not in a_minus_b: # b에는 있지만 a에 있는 건 b의 차집합이다. 따라서 Union에 추가한다. + union.append(i) + else: # a_minus_b는 a의 차집합으로 b와 중복되는 게 있다면 지워야 한다. + a_minus_b.remove(i) + + # 2.2. 다중교집합 구하기 + inter_set = [] + for i in b: + if i in a: + a.remove(i) + inter_set.append(i) + + # 3. 자카드 유사도 계산 + if len(union) == 0: # 합집합이 0이라면 + return 65536 + + similarity = len(inter_set) / len(union) + + # 정답 출력 + return int(similarity * 65536) \ No newline at end of file