Skip to content

Commit 6a44162

Browse files
authored
Merge pull request #49 from zaqquum/main
김홍주/7월5주차/3문제
2 parents 0e73631 + f74f4e7 commit 6a44162

File tree

3 files changed

+163
-0
lines changed

3 files changed

+163
-0
lines changed

Hongjoo/lv1/모의고사.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""
2+
num1 = [1,2,3,...n ] * len(answers) 반복
3+
num2 = [2, 1, 2, 3, 2, 4, 2, 5] 반복
4+
num3 = [3,3,1,1,2,2,4,4,5,5 반복
5+
6+
idea : 답 point = 문제 번호 % 패턴 개수
7+
8+
"""
9+
def solution(answers):
10+
answer = [0] *3
11+
num1 = [1,2,3,4,5]
12+
num2 = [2, 1, 2, 3, 2, 4, 2, 5]
13+
num3 = [3,3,1,1,2,2,4,4,5,5]
14+
# 0. 패턴 정의하기
15+
patterns = [num1, num2, num3]
16+
# 1.정답 개수 세기
17+
for i in range(len(answers)):
18+
for j in range(3):
19+
pattern = patterns[j]
20+
p= i % len(pattern) # point이용
21+
if pattern[p] == answers[i]:
22+
answer[j]+=1
23+
24+
#2. 가장 많이 맞춘 사람(중복 고려)
25+
max_idx = []
26+
max_num = max(answer) #2-1 가장 많이(max) 맞춘 개수 찾기
27+
for i in range(len(answer)) : # 2-2. 3명 돌면서 max 중복 값 가진 사람 idx 색출 -> 추가
28+
if max_num == answer[i] :
29+
max_idx.append(i+1)
30+
print(max_idx)
31+
32+
33+
return max_idx

Hongjoo/백준/감시피하기.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
"""
2+
role : 1. T , S , O
3+
T - 상하좌우 like 룩
4+
- 장애물 막히면 뒤에 못봄
5+
6+
1. T 가 볼 수 있는 영역 -> S 탐색 여부 확인
7+
2.
8+
9+
10+
"""
11+
import sys
12+
def backtracking(cnt):
13+
global flag
14+
15+
# 3개 장애믈 설치 끝나면
16+
if cnt == 3 :
17+
# 선생님들 위치에서 감시
18+
if check_S():
19+
flag = True # 성공하면 flag를 True로 초기화
20+
return True
21+
else : # 모든 빈 공간에 장애물 3개씩 설치해보기
22+
for x in range(n):
23+
for y in range(n) :
24+
if graph[x][y] == "X":
25+
graph[x][y] = "O"
26+
backtracking(cnt+1) # backtraking
27+
graph[x][y] = "X"
28+
29+
30+
def check_S() :
31+
#check_S : 선생님 시야 함수 (bfs -> 근데 dfs에 가깝지 않나???)
32+
#check = True # T가 S 를 못 찾음
33+
34+
# 상하좌우 움직이는 배열
35+
dx = [1,-1,0,0]
36+
dy = [0,0,1,-1]
37+
38+
for t in teachers : # 선생님 위치에서
39+
40+
for k in range(4): #상하좌우 탐색
41+
nx = t[0] + dx[k]
42+
ny = t[1] + dy[k]
43+
# 선생님 x,y 좌표
44+
while 0 <= nx < n and 0 <= ny < n : # graph 범위 밖 넘어가는 것 차단
45+
if graph[nx][ny] == "O" : #방애물 있으면 해당 방향 스킵
46+
break
47+
if graph[nx][ny] == "S" : # S 가 있으면 실패
48+
return False
49+
nx += dx[k]
50+
ny += dy[k]
51+
52+
# 모두 통과하면 S가 안보이는 것으로 성공
53+
return True
54+
55+
56+
# input 받기 - graph , T 위치 , X 위치
57+
n = int(sys.stdin.readline())
58+
flag = False # (답) 전체 시야 차단 yes or no
59+
graph = [] # 전체 MAP 위치
60+
teachers = list () # 선생님 (T) 좌표
61+
62+
for i in range(n):
63+
graph.append(list(map(str , sys.stdin.readline().split())))
64+
for j in range(n):
65+
if graph[i][j] == "T": # 선생님 있는 좌표 저장
66+
teachers.append([i,j])
67+
68+
69+
# BFS
70+
backtracking(0)
71+
72+
if flag :
73+
print("YES")
74+
else :
75+
print("NO")

Hongjoo/백준/경쟁적전염.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
"""
2+
1. bfs
3+
- queue
4+
- 인접 node
5+
(x,y) = [(x+1,y),(x-1,y),(x,y+1),(x,y-1)]
6+
2. sorting
7+
낮은 번호부터
8+
"""
9+
from collections import deque
10+
n, k = map(int, input().split())
11+
graph=[[] for _ in range(n)]
12+
for i in range(n):
13+
graph[i]=list(map(int,input().split()))
14+
s,x,y = map(int, input().split())
15+
print(graph)
16+
# 1.번호 순대로 초기 바이러스 정보 정렬
17+
virus_info = []
18+
for i in range(n):
19+
for j in range(n):
20+
if graph[i][j] != 0:
21+
virus_info.append([graph[i][j],0,[i,j]]) # [번호,시간,위치]
22+
#2.dfs
23+
# virus_info == queue
24+
virus_info.sort()
25+
print(virus_info)
26+
t=0
27+
while t < s :
28+
virus_info.sort()
29+
for node in virus_info:
30+
print("t",t ,"=",virus_info)
31+
queue = deque([node])
32+
now = queue.popleft()
33+
num , t , position = now
34+
near_nodes= [[position[0],position[1]+1],
35+
[position[0],position[1]-1],
36+
[position[0]-1,position[1]],
37+
[position[0]+1,position[1]]
38+
] # 상하좌우
39+
40+
t+=1
41+
if t > s :
42+
break
43+
for v in near_nodes: # v = [x,y]
44+
if n> v[0] and v[0]>= 0 and n> v[1] and v[1]>= 0 :
45+
if graph[v[0]][v[1]] == 0 :
46+
virus_info.append([num,t,v]) # 번호, 시간, 위치
47+
graph[v[0]][v[1]] = num
48+
print(f"graph node = {node}, => {graph}")
49+
# print(f"graph {v[0]},{v[1]}:{graph[v[0]][v[1]]}")
50+
# print(f"num, t, position {num} , {t} , {position}")
51+
52+
# print("#",virus_info)
53+
# print("##",graph)
54+
# print("###", graph[x][y])
55+
print(graph[x-1][y-1])

0 commit comments

Comments
 (0)