목록그리디 (88)
넘치게 채우기
https://leetcode.com/problems/prime-subtraction-operation/description/?envType=daily-question&envId=2024-11-11leetcode - Prime Subtraction Operation문제 유형: 정수론, 수학, 그리디문제 난이도: Medium 문제You are given a 0-indexed integer array nums of length n.You can perform the following operation as many times as you want:Pick an index i that you haven’t picked before, and pick a prime p strictly less than nums[..
https://leetcode.com/problems/minimum-number-of-changes-to-make-binary-string-beautiful/description/?envType=daily-question&envId=2024-11-05leetcode - Minimum Number of Changes to Make Binary String Beautiful문제 유형: 문자열 처리, 그리디문제 난이도: Medium 문제You are given a 0-indexed binary string s having an even length.A string is beautiful if it's possible to partition it into one or more substrings such tha..
https://codeforces.com/contest/2033/problem/DCodeforces Round 981(Div.3) - D. Kosuke's Assignment문제 유형: 부분합, 그리디, 다이나믹 프로그래밍시간 제한: 2초메모리 제한: 256MB 문제After a trip with Sakurako, Kousuke was very scared because he forgot about his programming assignment.In this assignment, the teacher gave him an array a">a of n">n integers and asked him to calculate the number of non-overlapping segments of the a..
https://codeforces.com/contest/2033/problem/CCodeforces Round 981(Div.3) - C. Sakurako's Field Trip문제 유형: 투 포인터, 그리디시간 제한: 2초메모리 제한: 256MB 문제Even in university, students need to relax. That is why Sakurakos teacher decided to go on a field trip. It is known that all of the students will be walking in one line. The student with index i">i has some topic of interest which is described as ai">a_i.A..
https://www.acmicpc.net/problem/16953BOJ - A → B문제 유형: 그리디, BFS, DFS문제 난이도: Silver II시간 제한: 2초메모리 제한: 512MB 문제정수 A를 B로 바꾸려고 한다. 가능한 연산은 다음과 같은 두 가지이다.2를 곱한다.1을 수의 가장 오른쪽에 추가한다. A를 B로 바꾸는데 필요한 연산의 최솟값을 구해보자. 입력첫째 줄에 A, B (1 ≤ A 9)가 주어진다. 출력A를 B로 바꾸는데 필요한 연산의 최솟값에 1을 더한 값을 출력한다. 만들 수 없는 경우에는 -1을 출력한다. 풀이B에서 A로 역변환하는 경로는 단 하나 뿐이므로, B에서 만들어볼 수 있다.예를 들어, b가 2의 배수인 동안, 2로 나누고, 일의자리수가 1이면 10으로 나누면 되겠다...
https://leetcode.com/problems/remove-sub-folders-from-the-filesystem/description/?envType=daily-question&envId=2024-10-25leetcode - Remove Sub-Folders from the Filesystem문제 유형: 문자열 처리, 그리디, 트라이(Trie)문제 난이도: Medium 문제Given a list of folders folder, return the folders after removing all sub-folders in those folders. You may return the answer in any order.If a folder[i] is located within another fo..
https://leetcode.com/problems/maximum-swap/description/leetcode - Maximum Swap문제 유형: 그리디, 수학문제 난이도: Medium 문제You are given an integer num. You can swap two digits at most once to get the maximum valued number.Return the maximum valued number you can get. 정수 num을 입력받습니다. 자릿수에서 두 개의 숫자를 바꿔서 최대값의 숫자로 변환할 수 있습니다.얻을 수 있는 최대값의 숫자를 출력하시오. 풀이브루트 포스 방법과, 인덱스를 이용한 방법이 있다.브루트 포스로는, 자릿수마다 다 한 번씩 스왑해보면서 최대 값..
https://leetcode.com/problems/separate-black-and-white-balls/description/?envType=daily-question&envId=2024-10-15leetcode - Separate Black and White Balls문제 유형: 투 포인터, 그리디문제 난이도 : Medium 문제There are n balls on a table, each ball has a color black or white.You are given a 0-indexed binary string s of length n, where 1 and 0 represent black and white balls, respectively.In each step, you can choos..
https://www.acmicpc.net/problem/1931BOJ - 회의실 배정문제 유형: 정렬, 그리디문제 난이도: Silver I시간 제한: 2초메모리 제한: 128MB 문제한 개의 회의실이 있는데 이를 사용하고자 하는 N개의 회의에 대하여 회의실 사용표를 만들려고 한다. 각 회의 I에 대해 시작시간과 끝나는 시간이 주어져 있고, 각 회의가 겹치지 않게 하면서 회의실을 사용할 수 있는 회의의 최대 개수를 찾아보자. 단, 회의는 한번 시작하면 중간에 중단될 수 없으며 한 회의가 끝나는 것과 동시에 다음 회의가 시작될 수 있다. 회의의 시작시간과 끝나는 시간이 같을 수도 있다. 이 경우에는 시작하자마자 끝나는 것으로 생각하면 된다. 입력첫째 줄에 회의의 수 N(1 ≤ N ≤ 100,000)이 주..
https://www.acmicpc.net/problem/30892BOJ - 상어 키우기문제 유형: 스택, 그리디문제 난이도: Silver I시간 제한: 1.5초메모리 제한: 1024MB 문제인천대학교의 앞바다에는 N마리의 상어가 살고 있다고 한다. 각각의 상어는 서로 같거나 다른 크기의 몸집 A_i를 가지고 있다. 상어의 세계는 완전한 약육강식의 세계로, 상어 자신의 크기보다 작은 상어는 전부 먹을 수 있다. 이때, 상어의 크기는 잡아먹힌 상어의 크기만큼 커지게 된다. 반면, 자신의 크기 이상인 상어는 전혀 잡아먹지 못한다.어느 날 크기가 T인 샼이라는 이름의 아기 상어는 인천대학교 앞바다에 존재하는 N마리 상어들의 크기 정보를 모두 입수했다. 똑똑한 아기 상어 샼은 인천대학교 앞바다에 있는 상어들을 ..