Upload files to "백준"

This commit is contained in:
2026-04-11 11:48:34 +09:00
parent f455d362b7
commit 738342b1ed
5 changed files with 150 additions and 0 deletions

50
백준/1926.py Normal file
View File

@@ -0,0 +1,50 @@
from collections import deque
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
result = []
N=int(input())
arr = [[0] * N for i in range(N)]
visited = [[False] * N for i in range(N)]
for i in range(N):
numbers = list(input())
for j in range(N):
arr[i][j] = int(numbers[j])
def BFS(i, j):
chance = 0
queue = deque()
queue.append((i,j))
visited[i][j]=True
while queue:
now = queue.popleft()
chance += 1
for k in range(4):
x = now[0] + dx[k]
y = now[1] + dy[k]
if(x >= 0 and y >= 0 and x<N and y<N):
if (visited[x][y]==False and arr[x][y]==True):
visited[x][y]=True
arr[x][y]=arr[now[0]][now[1]]+1
queue.append((x,y))
return chance
for i in range(N):
for j in range(N):
if (not visited[i][j] and arr[i][j]!=0):
k=BFS(i,j)
if(k!=0):
result.append(k)
else:
visited[i][j]=True
result.sort()
print(len(result))
for i in range(len(result)):
print(result[i])

21
백준/1931.py Normal file
View File

@@ -0,0 +1,21 @@
import sys
input = sys.stdin.readline
N = int(input().rstrip())
arr = []
for i in range(N):
j, k = map(int, input().split())
arr.append((j,k))
arr.sort(key=lambda x : (x[1], x[0])) #중요, 블로그에 메모해두기
min_val=-1
tot=0
for start, end in arr:
if(min_val<=start):
min_val=end
tot+=1
print(tot)

10
백준/1941.py Normal file
View File

@@ -0,0 +1,10 @@
import sys
input = sys.stdin.readline
arr=[]
for i in range(5):
arr.append(list(map(str, input().strip())))
dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]

16
백준/1947.py Normal file
View File

@@ -0,0 +1,16 @@
import sys
input = sys.stdin.readline
N = int(input())
D = [0] * (N+5)
D[0] = 0
D[1] = 0
D[2] = 1
D[3] = 2
for i in range(3, N+1):
D[i] = ((i-1) * (D[i-2] + D[i-1]))%1000000000
print(D[N])

53
백준/1948.py Normal file
View File

@@ -0,0 +1,53 @@
import sys
import math
from collections import deque
input = sys.stdin.readline
# 목표는 만나는 최소 시간과 최소시간에 모든 시간을 다 쓰는 사람의 지나는 도로의 수 카운트
n = int(input()) # 도시 수
m = int(input()) # 도로 수
cityisdegree = [0] * (n+1) # 도시에 대한 진입차수
maxtime = [0] * (n+1) #걸리는 최대 시간
visitedcityroad = [0] * (n+1) # 방문하는 도시의 최대 수 (최대 시간 걸리는 사람이 방문하는 도시의 최대 수)
a = [[] for _ in range(n+1)] # 모든 이어진 도로 정보
reverseA = [[] for _ in range(n+1)] # 모든 이어진 역방향 도로 정보
for i in range(m):
s, e, min = map(int, input().split()) # 출발 도시, 도착도시, 소요시간
cityisdegree[e] += 1
a[s].append((e, min))
reverseA[e].append((s, min))
s_city, e_city = map(int, input().split()) # 시작 도시, 도착도시
queue = deque()
queue.append(s_city)
while queue:
now = queue.popleft()
for e, min in a[now]:
maxtime[e] = max(maxtime[e], maxtime[now]+min) # 이 로직 맞는지 점검이 필요할듯?
cityisdegree[e] -= 1
if (cityisdegree[e]==0):
queue.append(e)
resultCount = 0 # 방문 최대횟수
visited = [False] * (n+1)
queue.clear()
queue.append(e_city)
while queue:
now = queue.popleft()
for s, min in reverseA[now]:
if(maxtime[now] == maxtime[s] + min):
resultCount+=1
if not visited[s]:
visited[s] = True
queue.append(s)
print(maxtime[e_city])
print(resultCount)