10775. 공항
10775번: 공항
예제 1 : [2][?][?][1] 형태로 도킹시킬 수 있다. 3번째 비행기는 도킹시킬 수 없다. 예제 2 : [1][2][3][?] 형태로 도킹 시킬 수 있고, 4번째 비행기는 절대 도킹 시킬 수 없어서 이후 추가적인 도킹은 불
www.acmicpc.net
- 다른 사람 풀이
#1,g까지 게이트
#1, i번째게이트 중 하나에 도킹
#앞 비행기 도킹 불가 -> break
#최대 도킹 수
def union(x,y):
xroot=find(x)
yroot=find(y)
if xroot<=yroot:
root[yroot]=xroot
else:
root[xroot]=yroot
def find(x):
if x!=root[x]:
root[x]=find(root[x])
return root[x]
g=int(input())
p=int(input())
plane=[]
for _ in range(p):
plane.append(int(input()))
root=[i for i in range(g+1)]
cnt=0
for pp in plane:
px=find(pp)
if px==0: # 가능한 게이트가 0이면 이후 전부 도킹 불가
break
union(px,px-1) # 다음 비행기가 사용할 수 있는 가장 큰 게이트 번호로 바꾼다
cnt+=1
print(cnt)
'코딩테스트 > BOJ' 카테고리의 다른 글
| [백준] [DP] 1149. RGB 거리 (0) | 2023.04.05 |
|---|---|
| [백준][BFS] 16918. 봄버맨 (0) | 2023.04.05 |
| [백준] 2812.크게 만들기 (0) | 2023.04.01 |
| [백준] 1092. 배 (0) | 2023.04.01 |
| [백준] 1946. 신입사원 (0) | 2023.04.01 |