본문 바로가기
728x90
320x100

💻 하나씩 차곡차곡/백준알고리즘 (Python,Java)13

백준 11650번 파이썬 문제 링크 : https://www.acmicpc.net/problem/11650 구현N = int(input())arr = [list(map(int, input().split())) for _ in range(N)]arr = sorted(arr)for x, y in arr: print(x, y)sorted() 즉 정렬 알고리즘을 활용. 풀이arr = [list(map(int, input().split())) for _ in range(N)]# [[3, 4], [1, 1], [1, -1], [2, 2], [3, 3]]arr은 위와 같이 출력된다. 2024. 10. 14.
백준 10974번 파이썬 문제 링크 : https://www.acmicpc.net/problem/10974 구현from itertools import permutationsN = int(input())for permutation in permutations(range(1, N + 1)): print(' '.join(map(str, permutation)))순열 알고리즘 사용. 2024. 10. 11.
백준 1759번 파이썬 문제링크 : https://www.acmicpc.net/problem/1759 구현from itertools import combinationsmo_list = ['a', 'e', 'i', 'o', 'u']def is_possible(word): global L, arr mo_cnt = 0 for w in word: mo_cnt += (w in mo_list) ja_cnt = chose_num - mo_cnt return (mo_cnt >=1 and ja_cnt >= 2)chose_num , total_num = map(int, input().split())arr = input().split()arr.sort()for word in combinations(arr, chose_num): if is_pos.. 2024. 10. 10.
백준 6603번 파이썬 문제 링크 : https://www.acmicpc.net/problem/6603 구현from itertools import combinationswhile True: I = list(map(int, input().split())) k = I[0] arr = I[1:] if k == 0: break for comb in combinations(arr, 6): for u in comb: print(u, end=' ') print() print()Cmbinations 함수를 활용하면 모든 경우의 수를 뽑을 수 있음 2024. 10. 9.
백준 4779번 파이썬 문제링크 : https://www.acmicpc.net/problem/4779 구현answer = ['' for _ in range(13)]answer[0] = '-'for i in range(1, 13): answer[i] = answer[i-1] + (' ' * (3 ** (i-1))) + answer[i-1]while True: try: N = int(input()) print(answer[N]) except: break 풀이예시를 보면 이런 규칙이 도출되어 이 알고리즘을 구현하면 됨. 2024. 10. 8.
백준 10870번 파이썬 문제 링크 : https://www.acmicpc.net/problem/10870 구현num = int(input())result_list = [];cnt = 0def fun (num): global cnt while True: if len(result_list) == 0: result_list.append(0) cnt += 1 elif len(result_list) == 1 : result_list.append(1) cnt += 1 elif len(result_list) == num + 1: cnt += 1 break; else : result_list.append(result_list[len(result_list) - 1] + result_list[len(result.. 2024. 10. 7.
728x90
320x100