일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
- 머신러닝
- rest api
- HTTP
- 캐싱
- 깊이우선탐색
- 알고리즘
- 프로그래머스
- 코딩테스트
- 멱등
- 자바
- 코딩
- 백준
- 코테
- 딥러닝
- post
- 파이썬
- 오버라이딩
- 강화학습
- 너비우선탐색
- 비지도학습
- 지도학습
- 이진탐색
- 해시
- 스택과 힙
- 파이썬 알고리즘
- Merge sort
- 파이썬 오류
- bineary search
- 딕셔너리
- BOJ
- Today
- Total
목록파이썬 알고리즘/BOJ (25)
chae._.chae
import sysfrom collections import defaultdictinput = sys.stdin.readlineN, M = map(int, input().split())words = []words_dict = defaultdict(int)for _ in range(N): word = input().rstrip() words.append(word) words_dict[word] += 1for key in list(words_dict): if len(key) 📌 다시 봐야 할 부분 1. 딕셔너리에서 아래처럼 for문을 통해 key으로 제거하려 하면 오류남for key, value in words_dict.items(): if len(key) RuntimeEr..
import sysinput = sys.stdin.readlineN = int(input())distances = list(map(int, input().split()))costs = list(map(int, input().split()))# 처음에는 시작지점에서 기름 넣고 시작total = costs[0]*distances[0]min_cost = costs[0]for i in range(1, N-1): if min_cost > costs[i]: min_cost = costs[i] total += min_cost*distances[i]print(total) 풀엇는데 또또또 까먹음..
import sysinput = sys.stdin.readlineN = int(input()) # 굴다리 길이M = int(input()) # 가로등 갯수lights = list(map(int, input().split())) # 설치 위치heights = lights[0] # 초기 높이는 첫번째 가로등 위치로end = lights[0]for i in range(1, len(lights)): tmp = abs(end-lights[i]) if tmp % 2 == 0: tmp = tmp // 2 else: tmp = tmp // 2 + 1 heights = max(heights, tmp) end = lights[i]# 맨 마지막 가로등 비교heigh..
https://www.acmicpc.net/problem/9017 import sysfrom collections import defaultdictinput = sys.stdin.readlineT = int(input())while T: # 각 팀당 선수 몇명인지 계산후, 여섯보다 작으면 모두 삭제 N = int(input()) players = list(map(int, input().split())) team_count = defaultdict(int) # 선수 카운트 team_dict = defaultdict(list) for i in players: team_count[i] += 1 # print(team_count) # {1: 6, 2: 2,..
https://www.acmicpc.net/problem/1244 import sysinput = sys.stdin.readlinedef on_off(i): if switch[i] == 0: switch[i] = 1 else: switch[i] = 0def same_switch(switch, pos): on_off(pos-1) for i in range(1, N//2): left = pos-i-1 right = pos+i-1 if left >= 0 and right 스위치 입력을 인덱스가 0인 것부터 받아서 마지막에 출력시 나머지가 19인 지점에서 줄바꿈 해줬다...
https://www.acmicpc.net/problem/1205 import sysfrom collections import defaultdictinput = sys.stdin.readlineN, new_score, P = map(int, input().split())scores = list(map(int, input().split()))# 등수 계산def get_rank(scores, new_score): dict = defaultdict(int) for num in scores: dict[num] += 1 answer = 0 for key, value in dict.items(): if key == new_score: answer +..
https://www.acmicpc.net/problem/20125import sysinput = sys.stdin.readlineN = int(input())graph = [list(input().rstrip()) for _ in range(N)]# print(graph)dx = [-1, 1, 0, 0]dy = [0, 0, -1, 1]# 심장위치 먼저 찾기 -> 상하좌우 확인해서 모두 *인 지점for i in range(1, N-1): for j in range(1, N-1): flag = [] for m in range(4): nx = i + dx[m] ny = j + dy[m] if graph[nx][ny] =..
내 풀이SOLVE1) 파이썬 defaultdict 이용 import sysfrom collections import defaultdictinput = sys.stdin.readlineN = int(input())nums = list(map(int, input().split()))dict = defaultdict(int)for i in nums: dict[i] += 1M = int(input())targets = list(map(int, input().split()))for i in targets: print(dict[i], end=' ') SOLVE2) Counter 모듈 사용 import sysfrom collections import Counterinput = sys.stdin.read..

https://www.acmicpc.net/problem/11053 11053번: 가장 긴 증가하는 부분 수열 수열 A가 주어졌을 때, 가장 긴 증가하는 부분 수열을 구하는 프로그램을 작성하시오. 예를 들어, 수열 A = {10, 20, 10, 30, 20, 50} 인 경우에 가장 긴 증가하는 부분 수열은 A = {10, 20, 10, 30, 20, 50} 이 www.acmicpc.net import sys input = sys.stdin.readline N = int(input()) A = list(map(int, input().split())) dp = [1] * 10001 for i in range(N): for j in range(i): if A[i] > A[j]]: dp[i] = max(dp[i..
https://www.acmicpc.net/problem/2178 2178번: 미로 탐색 첫째 줄에 두 정수 N, M(2 ≤ N, M ≤ 100)이 주어진다. 다음 N개의 줄에는 M개의 정수로 미로가 주어진다. 각각의 수들은 붙어서 입력으로 주어진다. www.acmicpc.net # 2178 미로 탐색 import sys from collections import deque input = sys.stdin.readline N, M = map(int, input().split()) matrix = [] for _ in range(N): matrix.append(list(map(int, input().rstrip()))) dx = [-1, 1, 0, 0] dy = [0, 0, 1, -1] # 너비우선탐색 d..