Python/CoTe 70

[programmers] 크레인 인형 뽑기

https://programmers.co.kr/learn/courses/30/lessons/64061 코딩테스트 연습 - 크레인 인형뽑기 게임 [[0,0,0,0,0],[0,0,1,0,3],[0,2,5,0,1],[4,2,4,4,2],[3,5,1,3,1]] [1,5,3,5,1,2,1,4] 4 programmers.co.kr # 주의 : 열의 모든 행을 검사 해야함 def solution(board, moves): answer = 0 bucket = [] for move in moves: for i in range(len(board)): # moves에 저장된 열의 모든 행마다 검사 if board[i][move-1] == 0: continue else: bucket.append(board[i][move-1]..

Python/CoTe 2022.02.19

[programmers] 완주하지 못한 선수

첫 번째 코드 - 정확도 통과, 효율성 통과X list 의 pop, remove은 너무 오래 걸린다. def solution(participants, completions): answer = '' for c in completions: participants.pop(participants.index(c)) return participants[0] 두 번쨰 코드 from collections import defaultdict def solution(participants, completions): answer = '' unfinished = defaultdict(int) for p in participants: unfinished[p] += 1 for c in completions: unfinished[c..

Python/CoTe 2022.02.19

[programmers] 숫자 문자열과 영단어

https://programmers.co.kr/learn/courses/30/lessons/81301 코딩테스트 연습 - 숫자 문자열과 영단어 네오와 프로도가 숫자놀이를 하고 있습니다. 네오가 프로도에게 숫자를 건넬 때 일부 자릿수를 영단어로 바꾼 카드를 건네주면 프로도는 원래 숫자를 찾는 게임입니다. 다음은 숫자의 일부 자 programmers.co.kr eng_num_dict = {'one':1, 'two':2, 'three':3, 'four':4, 'five':5, 'six':6, 'seven':7, 'eight':8, 'nine':9, 'zero':0} num = [0,1,2,3,4,5,6,7,8,9] def solution(s): tmp = '' answer = '' for letter in s..

Python/CoTe 2022.02.19

[programmers] 포켓몬

https://programmers.co.kr/learn/courses/30/lessons/1845# 코딩테스트 연습 - 폰켓몬 당신은 폰켓몬을 잡기 위한 오랜 여행 끝에, 홍 박사님의 연구실에 도착했습니다. 홍 박사님은 당신에게 자신의 연구실에 있는 총 N 마리의 폰켓몬 중에서 N/2마리를 가져가도 좋다고 했습니다. programmers.co.kr 처음 코드 from itertools import combinations def solution(nums): answer = 0 N = len(nums) if len(set(nums)) >= int(N/2): answer = int(N/2) else: comb_l = combinations(nums, int(N/2)) for c in set(comb_l): ..

Python/CoTe 2022.02.19

[BFS/DFS] 연구소

https://www.acmicpc.net/problem/14502 tep list 를 하나 만들어야 하는데, tmp = graph 하면, tmp가 변경될 때 참조주소를 복사 하는것이기 때문에 수정 및 삭제에 graph도 같이 변경된다. 찾아보니, tmp = list(graph) 이나 tmp=graph.copy() 하면 tmp 값이 변경될 때 graph는 유지 된다고 함. graph = [0, 0, 0, 0] tmp = list(graph) for i in range(len(tmp)): tmp[i] = i+1 print(tmp) print(graph) #output #[1, 2, 3, 4] #[0, 0, 0, 0] 코드가 심플할 때는 영향이 없는 것 같지만, 함수 안에서 리스트 복사용으로 사용하면 영향으..

Python/CoTe 2021.12.02

[BFS]경쟁적 전염 파이썬

출처: https://www.acmicpc.net/problem/18405 문제 NxN 크기의 시험관이 있다. 시험관은 1x1 크기의 칸으로 나누어지며, 특정한 위치에는 바이러스가 존재할 수 있다. 모든 바이러스는 1번부터 K번까지의 바이러스 종류 중 하나에 속한다. 시험관에 존재하는 모든 바이러스는 1초마다 상, 하, 좌, 우의 방향으로 증식해 나간다. 단, 매 초마다 번호가 낮은 종류의 바이러스부터 먼저 증식한다. 또한 증식 과정에서 특정한 칸에 이미 어떠한 바이러스가 존재한다면, 그 곳에는 다른 바이러스가 들어갈 수 없다. 시험관의 크기와 바이러스의 위치 정보가 주어졌을 때, S초가 지난 후에 (X,Y)에 존재하는 바이러스의 종류를 출력하는 프로그램을 작성하시오. 만약 S초가 지난 후에 해당 위치에..

Python/CoTe 2021.12.01
728x90