Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 노래합성
- Vocoder
- 음성 합성
- deep voice
- 한국어 tts
- TTS
- 보코더
- 딥러닝 보코더
- YOLO
- tacotron
- singing voice synthesis
- 학습
- 트레이닝
- 딥러닝
- 딥러닝 음성 합성
- you only look once
- 타코트론
- 윈도우
- melgan
- DCTTS
- korean tts
- 한국어 음성 합성
- waveglow
- text-to-speech
Archives
- Today
- Total
chldkato
백준 2146 다리 만들기 (파이썬) 본문
https://www.acmicpc.net/problem/2146
2146번: 다리 만들기
여러 섬으로 이루어진 나라가 있다. 이 나라의 대통령은 섬을 잇는 다리를 만들겠다는 공약으로 인기몰이를 해 당선될 수 있었다. 하지만 막상 대통령에 취임하자, 다리를 놓는다는 것이 아깝다는 생각을 하게 되었다. 그래서 그는, 생색내는 식으로 한 섬과 다른 섬을 잇는 다리 하나만을 만들기로 하였고, 그 또한 다리를 가장 짧게 하여 돈을 아끼려 하였다. 이 나라는 N×N크기의 이차원 평면상에 존재한다. 이 나라는 여러 섬으로 이루어져 있으며, 섬이란 동서남북
www.acmicpc.net
섬의 가장자리에서 다음 섬에 도착할 때까지의 경로를 매번 bfs로 구했더니 런타임에러가 떴다
1. 섬이 몇개있는지 bfs로 구한다
2. 섬 중에서 하나를 선택해 섬의 크기를 늘려가면서 다른 섬에 닿을 때까지의 거리를 구한다.
3. 과정 2를 전체 섬에 대하여 구한 후 최소값을 출력
from collections import deque
import sys
input = sys.stdin.readline
dx = [1, -1, 0, 0]
dy = [0, 0, 1, -1]
def bfs1(x, y, cnt):
q.append([x, y])
c1[x][y] = cnt
while q:
x, y = q.popleft()
for i in range(4):
nx = x + dx[i]
ny = y + dy[i]
if 0 <= nx < n and 0 <= ny < n:
if a[nx][ny] == 1 and c1[nx][ny] == 0:
c1[nx][ny] = cnt
q.append([nx, ny])
def bfs2(num):
while q:
x, y = q.popleft()
for i in range(4):
nx = x + dx[i]
ny = y + dy[i]
if 0 <= nx < n and 0 <= ny < n:
if a[nx][ny] == 1 and c1[nx][ny] != num:
return c2[x][y]-1
if a[nx][ny] == 0 and c2[nx][ny] == 0:
c2[nx][ny] = c2[x][y] + 1
q.append([nx, ny])
n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
c1 = [[0]*n for _ in range(n)]
q, q2 = deque(), deque()
cnt = 1
for i in range(n):
for j in range(n):
if a[i][j] == 1 and c1[i][j] == 0:
bfs1(i, j, cnt)
cnt += 1
ans = sys.maxsize
for k in range(1, cnt):
q = deque()
c2 = [[0] * n for _ in range(n)]
for i in range(n):
for j in range(n):
if a[i][j] == 1 and c1[i][j] == k:
q.append([i, j])
c2[i][j] = 1
res = bfs2(k)
ans = min(ans, res)
print(ans)
'백준' 카테고리의 다른 글
백준 1963 소수 경로 (파이썬) (0) | 2020.02.17 |
---|---|
백준 9019 DSLR (파이썬) (0) | 2020.02.17 |
백준 2573 빙산 (파이썬) (0) | 2020.02.17 |
백준 5014 스타트링크 (파이썬) (0) | 2020.02.17 |
백준 1707 이분 그래프 (파이썬) (0) | 2020.02.16 |
Comments