2025/02/19 7

2346. 풍선터뜨리기

https://www.acmicpc.net/problem/2346✅ 문제를 잘 읽고 요구조건에 맞게 풀어야 합니다......      예시 입력과 출력은 어떤 방식으로 하든 잘 구현이 됩니다.. import syssys.stdin = open('input.txt')input = sys.stdin.readlinefrom collections import dequeN = int(input().strip())dq = deque(range(1,N+1))# 안에 들어있는 번호 ( N풍선이면 n-1 값이 들어가야함 ) 2번풍선 값은 1번 인덱스에 있는거임.num = list(map(int, input().split()))ans = []# 제일처음에는 1번 풍선을 터뜨리고 안에있는 번호로 이동해서 한다. (원형임)P..

Baekjoon 2025.02.19

11866. 요세푸스 문제 0

https://www.acmicpc.net/problem/11866 ✅ 원형 큐에 대해 이해해봅시다.import syssys.stdin = open('input.txt')input = sys.stdin.readlinefrom collections import deque# 원형 큐 문제N, K = map(int,input().split())queue = deque(range(1,N+1))ans = [] # queue 는 문자열 변환이나 출력할때 queue([]) 형태로 뜨므로 리스트로 저장while queue: # queue 에 남아있을 때까지 queue.rotate(-(K-1)) # K-1번 왼쪽으로 회전( K 번째 요소가 맨앞에 오도록) ans.append(queue.popleft()) # ..

Baekjoon 2025.02.19

2164. 카드 2

🚨시간초과가 나버려욧!import sysinput = sys.stdin.readlineN = int(input())arr = list(i for i in range(N,0,-1))while len(arr) > 1: arr.pop() arr.insert(0, arr.pop())print(arr[0]) 👌중간에 삽입 및 삭제가 많으므로 Dequeue 를 사용해야합니다.import sysinput = sys.stdin.readlinefrom collections import deque # 완전 기초 모듈N = int(input().strip())queue = deque(range(N,0,-1))while len(queue) > 1: queue.pop() queue.appendleft(..

Baekjoon 2025.02.19

1157. 단어 공부

https://www.acmicpc.net/problem/1157 # # 기본 세팅입니다.# import sys# sys.stdin = open('input.txt')# input = sys.stdin.readline# 문자열 입력값을 받는다. ( raw 데이터, 날것의 데이터를 먼저 받는다.)str_raw = input().strip() # 문자열 끝에 포함된 개행문자 없애줘야 해서 strip이 들어가야함.# 알파벳의 대소문자는 구분하지 않으므로 모두 대문자로 바꿔준다. ( 데이터 전처리 )string = str_raw.upper()# 알파벳을 카운트 할 수 있는 딕셔너리로 생성한다. ( 다른 방법도 있지만 딕셔너리 연습할겸 )alphabet = {}for char in string: ..

Baekjoon 2025.02.19