Programming [Python] (411) 썸네일형 리스트형 #264 백준 파이썬 [10995] 별 찍기 - 20 https://www.acmicpc.net/problem/10995 Python Code N = int(input()) if N == 1: print('*') else: for n in range(N): if n % 2 == 0: a = print('* ' * N) else: b = print(' *' * N) #263 백준 파이썬 [2583] 영역 구하기 - BFS https://www.acmicpc.net/problem/2583 Solution 1) M,N paper 배열을 만들어준 뒤, 직사각형에 해당하는 부분만 1로 바꾸어준다. 색종이 문제 https://claude-u.tistory.com/299 참고. 2) BFS 너비우선 탐색을 이용해서 직사각형에 해당하지 않는 부분 부분의 크기를 탐색해준다. 3) 함수에서는 block의 크기만 필요함으로 len(block)을 return해준다. 4) 이후 0,0부터 M,N까지 이중 for문을 돌려 BFS함수를 실행해준다. Python Code #블록이 몇개인지 알아내기 위한 BFS 너비 우선 탐색 함수를 정의 def bfs(i, j): global visited, paper if paper[i][j] == 1: #직사각.. #262 백준 파이썬 [1158] 조세퍼스 문제 https://www.acmicpc.net/problem/1158 Solution 1부터 N까지의 순열 josephus를 만든 뒤, 리스트를 도는 temp를 만든다. 맞는 숫자를 pop하여 result리스트에 넣는 방법을 통해 풀이할 수 있다. 이때 temp에 지속적으로 K-1을 더해줌으로써(1은 pop하면서 빠지기 때문) 다음 리스트를 찾는다. 위치가 리스트를 초과하면 리스트 길이로 나누어준 나머지를 pop해준다. Python Code #입력 N, K = map(int, input().split()) josephus = [i for i in range(1, N + 1)] result = [] temp = K - 1 for i in range(N): if len(josephus) > temp: #위치가 .. #261 백준 파이썬 [2566] 최댓값 https://www.acmicpc.net/problem/2566 Python Code max_num = 0 for i in range(9): row = list(map(int, input().split())) #굳이 행렬을 저장할 필요는 없다 if max(row) > max_num: max_num = max(row) #최댓값 x = i + 1 #행 y = row.index(max_num) + 1 #열 print(max_num) print(x,y) #260 백준 파이썬 [15663] N과 M (9) - 순열 https://www.acmicpc.net/problem/15663 Solution 리스트에 먼저 permutation 함수를 이용해 전부를 추가해주고 중복된 항목만 걸러주면 된다. 비효율적이지만 쉬운 set() 집합 함수를 이용해서 중복을 걸러주었다. 비효율적이고 중복을 없애주는 마법의 함수 --> A = list(set(A)) Python Code from itertools import permutations N, M = map(int, input().split()) N_list = list(map(int, input().split())) N_list = sorted(N_list) #순서대로 나오게 정렬 먼저 output = [] for numbers in list(permutations(N_list.. #259 백준 파이썬 [15665] N과 M (11) - 중복 순열 https://www.acmicpc.net/problem/15665 Python Code from itertools import product N, M = map(int, input().split()) N_list = list(map(int, input().split())) N_list = list(set(N_list)) #중복 값 제거 N_list = sorted(N_list) #순서대로 나오게 정렬 먼저 for numbers in list(product(N_list, repeat = M)): for num in numbers: print(num, end=' ') print() #258 백준 파이썬 [15666] N과 M (12) - 중복 조합 https://www.acmicpc.net/problem/15666 Python Code from itertools import combinations_with_replacement #중복 조합 N, M = map(int, input().split()) N_list = list(map(int, input().split())) N_list = sorted(N_list) #순서대로 나오게 정렬 먼저 output = [] for numbers in list(combinations_with_replacement(N_list, M)): if not output: output.append(numbers) elif numbers not in output: output.append(numbers) for numbers.. #257 백준 파이썬 [15664] N과 M (10) - 조합 https://www.acmicpc.net/problem/15664 Python Code from itertools import combinations N, M = map(int, input().split()) N_list = list(map(int, input().split())) N_list = sorted(N_list) #순서대로 나오게 정렬 먼저 output = [] #중복 제거하기 위한 리스트 생성 for numbers in list(combinations(N_list, M)): if not output: output.append(numbers) elif numbers not in output: # 중복 제거 output.append(numbers) for numbers in output: fo.. 이전 1 ··· 16 17 18 19 20 21 22 ··· 52 다음