-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from INIT-Algorithm/jiyoon
#26 : Week6_지윤이티
- Loading branch information
Showing
4 changed files
with
147 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#10026_적록색약 | ||
#적록색약이 아닌 사람 : 유기농 배추랑 똑같음 | ||
#적록색약인 사람 : | ||
import sys | ||
sys.setrecursionlimit(10000) | ||
|
||
read=sys.stdin.readline | ||
#MAX= 100+10 | ||
#print(MAX) | ||
n = int(read()) | ||
|
||
#인덱스0부터 3까지 차례대로 합치면 오른쪽, 왼쪽, 위, 아래 | ||
dirX = [1, -1, 0, 0] | ||
dirY = [0, 0, 1, -1] | ||
|
||
#graph | ||
graph = [list(input().rstrip()) for _ in range(n)] | ||
|
||
#visited | ||
visited=[[False]*(n) for _ in range(n)] | ||
|
||
count1 = 0 | ||
count2 = 0 | ||
|
||
|
||
def dfs(x,y): | ||
global graph, visited | ||
visited[x][y] = True | ||
|
||
for i in range(4): | ||
newX = x + dirX[i] | ||
newY = y + dirY[i] | ||
if (n > newX >= 0) and (n > newY >= 0): | ||
if not visited[newX][newY]: | ||
if graph[newX][newY] == graph[x][y]:#위 조건 만족하면서 탐색중인 색상과 같은 색이면 | ||
dfs(newX, newY) #dfs로 탐색 | ||
|
||
# 적녹색약이 아닌 사람 | ||
for i in range(0, n): | ||
for j in range(0, n): | ||
if graph[i][j] and not visited[i][j]: | ||
dfs(i, j) | ||
count1 += 1 | ||
|
||
# 적녹색약인 사람 | ||
# 초록색->빨간색으로 변경 | ||
for i in range(0, n): | ||
for j in range(0, n): | ||
if graph[i][j] == 'R': | ||
graph[i][j] = 'G' | ||
# 방문정보 초기화 | ||
visited = [[False]*(n) for _ in range(n)] | ||
for i in range(0, n): | ||
for j in range(0, n): | ||
if graph[i][j] and not visited[i][j]: | ||
dfs(i, j) | ||
count2 += 1 | ||
|
||
print(count1, count2) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import sys | ||
|
||
input = sys.stdin.readline | ||
INF = int(1e9) # 무한을 의미하는 값으로 10억 | ||
|
||
N = int(input()) | ||
|
||
alphabet = "abcdefghijklmnopqrstuvwxyz" | ||
|
||
n = len(alphabet) #26 | ||
|
||
graph = [[INF] * n for _ in range(n)] # INF로 초기화 | ||
|
||
for _ in range(N): | ||
a, b = map(alphabet.index, input().rstrip().split(" is ")) | ||
graph[a][b] = 1 | ||
|
||
for k in range(n): | ||
for a in range(n): | ||
for b in range(n): | ||
graph[a][b] = min(graph[a][b], graph[a][k] + graph[k][b]) | ||
|
||
M = int(input()) | ||
for _ in range(M): | ||
a, b = map(alphabet.index, input().rstrip().split(" is ")) | ||
if graph[a][b] == INF: | ||
print("F") | ||
else: | ||
print("T") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import sys | ||
|
||
input = sys.stdin.readline | ||
|
||
# k : 이미 가지고 있는 랜선의 개수, n : 필요한 랜선의 개수 | ||
k, n = map(int, input().split()) | ||
lan = [int(input()) for _ in range(k)] | ||
|
||
answer = 0 # 랜선의 최대 길이 | ||
|
||
start, end = 1, max(lan) | ||
while start <= end: | ||
mid = (start + end) // 2 | ||
temp_sum = 0 | ||
for i in lan: # mid 길이만큼 랜선 케이블들을 조각냄 | ||
temp_sum += i // mid | ||
|
||
if temp_sum >= n: # 랜선의 개수가 n이상이면 | ||
start = mid + 1 | ||
answer = mid | ||
else: # 랜선의 개수가 n미만이면 | ||
end = mid - 1 | ||
|
||
print(answer) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# 1931_회의실 배정 | ||
|
||
import sys | ||
|
||
# 회의의 수 | ||
n = int(sys.stdin.readline()) | ||
|
||
# 회의 시간 | ||
meeting_times = [] | ||
|
||
# 회의의 시작 시간과 끝나는 시간 | ||
for _ in range(n): | ||
start, end = map(int, sys.stdin.readline().split()) | ||
meeting_times.append((start, end)) | ||
|
||
# 회의 시간을 종료 시간 기준 및 시작 시간 기준으로 정렬 | ||
meeting_times = sorted(meeting_times, key = lambda x : (x[1], x[0])) | ||
|
||
# 최대 회의 개수 | ||
count = 1 | ||
# 이전 회의 종료 시간 | ||
end_time = meeting_times[0][1] | ||
|
||
for i in range(1, n): | ||
# 다음 회의 시작 시간이 이전 회의 종료 시간보다 크거나 같다면 | ||
if (meeting_times[i][0] >= end_time): | ||
# 이전 회의 종료 시간 업데이트 | ||
end_time = meeting_times[i][1] | ||
# 최대 회의 개수 증가 | ||
count += 1 | ||
|
||
print(count) |