공부 서랍장/알고리즘 공부 28

[프로그래머스] 소수만들기 python

# 문제 : https://school.programmers.co.kr/learn/courses/30/lessons/12977 from collections import deque tmp = [] def do_something(comb): return list(comb) def dfs(comb: deque, depth: int): M = 3 if len(comb) == M: # 종료 조건 1 : M개를 모두 선택했을 때 tmp.append(do_something(comb)) # 선택 후의 알고리즘 호출 return elif depth == len(some_list): # 종료 조건 2: 리스트의 마지막 까지 탐색했을 때 return # 현재 depth의 값 포함 재귀 호출 comb.append(some_..

[프로그래머스] 모의고사 python

# 문제: https://school.programmers.co.kr/learn/courses/30/lessons/42840 def student_answer(answers): student_1,student_2,student_3 = [],[],[] #수포자1,2,3 정답지 설정 tmp = [1,2,3,4,5] for i in range(0,len(answers)): student_1.append(tmp[i%5]) tmp = [2, 1, 2, 3, 2, 4, 2, 5] for i in range(0,len(answers)): student_2.append(tmp[i%8]) tmp = [3, 3, 1, 1, 2, 2, 4, 4, 5, 5] for i in range(0,len(answers)): stude..

[프로그래머스] 오픈채팅방 python

# 문제 https://school.programmers.co.kr/learn/courses/30/lessons/42888 global dic dic = {} def nick_name_update(ID,nick_name): ## 닉네임 저장 dic[ID] = nick_name return def solution(record): answer = [] tmp_answer = [] ## 닉네임 업데이트 by dict for i in record: action = i.split(sep=' ') if action[0] == 'Enter': nick_name_update(action[1],action[2]) tmp_answer.append([action[0],action[1]]) elif action[0] == '..

[백준] 16236번 아기상어 C/C++

//백준 아기상어 16236번 //www.acmicpc.net/problem/16236 #include #include #include #include using namespace std; int map[20][20]; int N; int fishSize = 2, fishCount = 2; int y, x; int dy[] = { -1,0,1,0 }; int dx[] = { 0,1,0,-1 }; bool chk[20][20]; int dist[20][20]; int eaty, eatx; int simulation() { int time = 0; memset(dist, 0, sizeof(dist)); //dist 전부 0으로 채우기 memset(chk, false, sizeof(chk)); //dhk 전부..

[백준] 14503번 로봇청소기 C/C++

//C/C++ 백준 로봇 청소기 //www.acmicpc.net/problem/14503 #include #include #include using namespace std; int n, m = 0; const int dy[] = { -1,0,1,0 }; //북동남서 const int dx[] = { 0,1,0,-1 }; //북동남서 int map[55][55]; int chk[55][55] = { false, }; struct robot { int x, y, d; }; robot r; int sol() { int result = 0; chk[r.y][r.x] = true; // 1) 현재의 위치를 먼저 청소한다. queue q; q.push(make_pair(make_pair(r.y,r.x..

728x90