분류 전체보기
-
[Python] 백준 11650 - 좌표 정렬하기Algorithm/백준 2021. 10. 12. 20:45
1. 문제 📚 https://www.acmicpc.net/problem/11650 11650번: 좌표 정렬하기 첫째 줄에 점의 개수 N (1 ≤ N ≤ 100,000)이 주어진다. 둘째 줄부터 N개의 줄에는 i번점의 위치 xi와 yi가 주어진다. (-100,000 ≤ xi, yi ≤ 100,000) 좌표는 항상 정수이고, 위치가 같은 두 점은 없다. www.acmicpc.net 2. 입출력 예 📋 3. 알고리즘 ✅ sorted 함수를 이용하여 정렬한다. ❗️ list를 sort 할 경우는 맨 앞을 기준으로 정렬한다. 4. 소스코드 💻 import sys input = sys.stdin.readline N = int(input()) nums = [] for i in range(N): [a, b] = map..
-
[Python] 입국심사Algorithm/프로그래머스 2021. 6. 3. 02:52
1. 문제 📚 2. 입출력 예 📋 3. 알고리즘 ✅ 코테의 이진 탐색 문제는 탐색범위가 큰 상황에서 탐색을 가정하는 문제가 많다. 따라서 탐색 범위가 클 경우 이진 탐색으로 문제에 접근해보자 ! 1. 일을 하는 데 소요하는 시간 min, max 정하기 min = 1 max = 가장 오래 걸리는 심사대 * 일의 개수 2. 각 입국 심사대에서 처리 한 일들이 n의 값이 되는 지 확인해보기 각 입국 심사대에서 일한 개수 = mid // n 3. mid 값 조정하기 - mid / time 이 n의 값보다 크다면, mid를 줄인다. - mid / time 이 n의 값보다 작다면, mid를 늘린다. 마지막 mid 값이 우리가 구하는 최소 값이 된다. 4. 소스코드 💻 def solution(n, times): st..
-
[Python] 백준 2193번 이친수Algorithm/백준 2021. 5. 17. 23:59
1. 문제 📚 2. 입출력 예 📋 3. 알고리즘 ✅ Dp 문제이므로 규칙 또는 점화식을 찾는다 N / 끝의 수 0 1 출력 값(갯수) 1 0 1 1 2 1 0 1 3 1 1 2 4 2 1 3 5 3 2 5 6 5 3 8 규칙을 보면, N이 1과, 2일 땐 1이며 그 이외엔 그 전에 값 2개를 합친 값과 출력 값이 같다는 규칙을 찾을 수 있다. 4. 소스코드 💻 n = int(input()) nums = [1] * n if n == 1 or n == 2: print(1) else: for i in range(2, n): nums[i] = nums[i-1] + nums[i-2] print(nums[n-1])
-
[Python] 백준 2438번 별찍기Algorithm/백준 2021. 5. 8. 22:00
1. 문제 📚 / 입출력 예 📋 3. 알고리즘 ✅ i 번을 받고 i번을 반복하여 별을 찍는다 4. 소스코드 💻 [내가 쓴 코드] n = int(input()) for i in range(1, n+1): while i != 0: print('*', end = '') i -= 1 print() [파이썬 다운 코드] n = int(input()) for i in range(1, n+1): print('*' * i) 파이썬은 string도 곱하기가 된다는 것을 기억하자❗️❗️
-
[Python] 로또의 최고 순위와 최저 순위Algorithm/프로그래머스 2021. 5. 5. 23:54
1. 문제 📚 2. 입출력 예 📋 3. 알고리즘 ✅ wins_num에는 같은 숫자가 담겨있지 않으므로, 0이 모두 맞으면, 최고 순위가 된다 최저순위는 0이 모두 안맞고, win_nums과 같은 숫자의 갯수가 최저 개수가 된다. 2개가 일치하는 것부터 순위를 주고, 나머지는 6위이므로 index를 맞은 갯수로 생각하고 리스트를 만들어 준다 따라서 최고 순위 = 일치하는 번호 갯수 + 0의 갯수 최저 순위 = 일치하는 번호 갯수 4. 소스코드 💻 def solution(lottos, win_nums): answer = 0 rank = [6, 6, 5, 4, 3, 2, 1] cnt_0 = lottos.count(0) for num in win_nums: if num in lottos: answer += 1 ..
-
[Python] 폰켓몬Algorithm/프로그래머스 2021. 5. 3. 23:21
1. 문제 📚 2. 입출력 예 📋 3. 알고리즘 ✅ 가장 많은 종류의 폰켓몬을 갖고 싶어하기 때문에 박사님이 가지고 있는 폰켓몬 /2 만큼 중복제거를 해준다 4. 소스코드 💻 def solution(nums): count=len(nums)//2 poketmon = [] for i in nums: if poketmon.count(i) == 0: poketmon.append(i) return len(poketmon[:count]) 5. 다른사람의 풀이 💻 def solution(nums): return min(len(nums)/2, len(set(nums))) 앞으로는 if 절로 중복을 제거하는 방법보단 set을 이용하자! 😅