Skip to content

Commit

Permalink
Merge branch 'main' into 23-H0ngJu
Browse files Browse the repository at this point in the history
  • Loading branch information
H0ngJu authored Aug 21, 2024
2 parents 9c598c7 + 883f980 commit 2dd22df
Show file tree
Hide file tree
Showing 11 changed files with 299 additions and 51 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import sys
from collections import deque

def input() : return sys.stdin.readline().rstrip()

t = int(input())
dx = [-1, 1, 0, 0]
dy = [0, 0, -1, 1]


for i in range(t):
n = int(input())
hx, hy = map(int, input().split())
store = [list(map(int, input().split())) for _ in range(n)]
fx, fy = map(int, input().split())

x, y = hx, hy
result = "sad"

q = deque([(x, y, 20)])
visited = set([x, y])

while q:
x, y, beer = q.popleft()

if abs(x-fx) + abs(y-fy) <= 50*beer: # ์ถ•์ œ๊นŒ์ง€ ๊ฐˆ ์ˆ˜ ์žˆ๋Š”์ง€
result = "happy"
break

for sx, sy in store: # ํŽธ์˜์  ๋“ค๋ฆด ์ˆ˜ ์žˆ๋Š”์ง€
if abs(x-sx) + abs(y-sy) <= 50 * beer and (sx, sy) not in visited:
visited.add((sx, sy))
q.append((sx, sy, 20))

if beer > 0: # beer ๋จน๊ณ  ๊ฐ€๊ธฐ
for i in range(4):
nx = x + dx[i]
ny = y + dy[i]

if (nx, ny) not in visited:
visited.add((nx, ny))
q.append((nx, ny, beer - 1))

print(result)

64 changes: 64 additions & 0 deletions H0ngJu/BFS/์•„๊ธฐ์ƒ์–ด.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import sys
from collections import deque

def input() : return sys.stdin.readline().rstrip()

N = int(input())
space = [list(map(int, input().split())) for _ in range(N)]

dir = [(0,1), (0,-1), (1,0), (-1,0)]
x = 0
y = 0

for i in range(N):
for j in range(N):
if space[i][j] == 9:
x, y = i, j
space[x][y] = 0

def check(a, b):
if 0<=a<N and 0<=b<N:
return True
return False

baby = 2

time = 0
fish = 0

while True:
q = deque([(x, y, 0)])
visited = [[False] * N for _ in range(N)]
visited[x][y] = True
min_dis = float('inf')
tmp = []

while q:
cx, cy, dis = q.popleft()

if 0 < space[cx][cy] < baby:
if dis < min_dis:
min_dis = dis
tmp = [(cx, cy)]
elif dis == min_dis:
tmp.append((cx, cy))

for dx, dy in dir:
nx, ny = cx + dx, cy + dy
if check(nx, ny) and not visited[nx][ny] and space[nx][ny] <= baby:
visited[nx][ny] = True
q.append((nx, ny, dis + 1))

if not tmp:
break

tx, ty = min(tmp)
space[tx][ty] = 0
time += min_dis
fish += 1
if fish == baby:
baby += 1
fish = 0
x, y = tx, ty

print(time)
3 changes: 2 additions & 1 deletion H0ngJu/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
| 19์ฐจ์‹œ | 2024.05.31 | DP | [ํ•ฉ๋ถ„ํ•ด](https://www.acmicpc.net/problem/2225) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/202 |
| 20์ฐจ์‹œ | 2024.06.03 | ๋ฐฑํŠธ๋ž˜ํ‚น | [์Šคํƒ€ํŠธ์™€ ๋งํฌ](https://www.acmicpc.net/problem/14889) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/206 |
| 21์ฐจ์‹œ | 2024.06.07 | ๊ทธ๋ฆฌ๋”” | [ํ–‰๋ณต ์œ ์น˜์›](https://www.acmicpc.net/problem/13164) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/208 |

| 22์ฐจ์‹œ | 2024.08.06 | ํ•ด์‹œ | [์˜์ƒ](https://school.programmers.co.kr/learn/courses/30/lessons/42578) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/224 |
| 23์ฐจ์‹œ | 2024.08.10 | ํ•ด์‹œ | [๋ฒ ์ŠคํŠธ์•จ๋ฒ”](https://school.programmers.co.kr/learn/courses/30/lessons/42579) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/227 |
| 24์ฐจ์‹œ | 2024.08.17 | BFS | [์•„๊ธฐ์ƒ์–ด](https://www.acmicpc.net/problem/16236) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/233 |

---
28 changes: 28 additions & 0 deletions H0ngJu/ํ•ด์‹œ/์˜์ƒ.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import sys
import itertools

def input() : return sys.stdin.readline().rstrip()

clothes = [["yellow_hat", "headgear"],
["blue_sunglasses", "eyewear"],
["green_turban", "headgear"],
["test1", "sample"],
["test2", "sample"],
]
c_dict = {}
answer = 1

for info in range(len(clothes)):
if not clothes[info][1] in c_dict:
c_dict[clothes[info][1]] = 1
else:
c_dict[clothes[info][1]] += 1

# answer = collections.Counter(c_dict)

for c in c_dict.values():
answer *= (c+1)

answer -= 1

print(answer)
Original file line number Diff line number Diff line change
@@ -1,51 +1,30 @@
import Foundation

func solution(_ maps: [[Int]]) -> Int {
var maps = maps
let dx = [-1, 1, 0, 0]
let dy = [0, 0, -1, 1]
let rowCount = maps.count
let colCount = maps[0].count

func bfs(_ x: Int, _ y: Int) -> Int {
var queue = [(x, y)]
var index = 0

while index < queue.count {
let (x, y) = queue[index]
index += 1

for i in 0..<4 {
let nx = x + dx[i]
let ny = y + dy[i]

if nx < 0 || nx >= rowCount || ny < 0 || ny >= colCount {
continue
}

if maps[nx][ny] == 0 {
continue
}

if maps[nx][ny] == 1 {
from collections import deque
def solution(maps):
answer = 0

dx = [-1, 1, 0, 0]
dy = [0, 0, -1, 1]

def bfs(x, y):
queue = deque()
queue.append((x, y))

while queue:
x, y = queue.popleft()

for i in range(4):
nx = x + dx[i]
ny = y + dy[i]

if nx < 0 or nx >= len(maps) or ny < 0 or ny >= len(maps[0]): continue

if maps[nx][ny] == 0: continue

if maps[nx][ny] == 1:
maps[nx][ny] = maps[x][y] + 1
queue.append((nx, ny))
}
}
}

return maps[rowCount - 1][colCount - 1]
}

let answer = bfs(0, 0)
return answer == 1 ? -1 : answer
}

// ์˜ˆ์‹œ ํ˜ธ์ถœ
let maps = [
[1, 0, 1, 1, 1],
[1, 0, 1, 0, 1],
[1, 1, 1, 0, 1],
[0, 0, 0, 0, 1]
]
print(solution(maps)) // ์ถœ๋ ฅ: 11

return maps[len(maps)-1][len(maps[0])-1]

answer = bfs(0, 0)
return -1 if answer == 1 else answer
3 changes: 2 additions & 1 deletion alstjr7437/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@
| 28์ฐจ์‹œ | 2024.05.30 | ๋ธŒ๋ฃจํŠธ ํฌ์Šค | <a href="https://www.acmicpc.net/problem/6064">์นด์ž‰ ๋‹ฌ๋ ฅ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/203 |
| 29์ฐจ์‹œ | 2024.06.11 | ์ด๋ถ„ ํƒ์ƒ‰ | <a href="https://www.acmicpc.net/problem/2805">๋‚˜๋ฌด ์ž๋ฅด๊ธฐ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/210 |
| 30์ฐจ์‹œ | 2024.06.19 | ๋ฐฉ ๋ฒˆํ˜ธ | <a href="https://www.acmicpc.net/problem/1475">๊ตฌํ˜„</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/211 |
| 31์ฐจ์‹œ | 2024.06.19 | ๊ฒŒ์ž„ ๋งต ์ตœ๋‹จ๊ฑฐ๋ฆฌ | <a href="https://school.programmers.co.kr/learn/courses/30/lessons/1844">BFS</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/218 |
| 31์ฐจ์‹œ | 2024.06.19 | ๊ฒŒ์ž„ ๋งต ์ตœ๋‹จ๊ฑฐ๋ฆฌ | <a href="https://school.programmers.co.kr/learn/courses/30/lessons/1844">BFS</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/218 |
| 32์ฐจ์‹œ | 2024.08.15 | ๊ณผ์ผ ํƒ•ํ›„๋ฃจ | <a href="https://www.acmicpc.net/problem/30804">ํˆฌ ํฌ์ธํ„ฐ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/230 |
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
N = int(input())
tanghuru = list(map(int, input().split()))
fruit = [0] * 10
kind = 0
start, end = 0, 0

while True:
if end == N:
print(end - start)
break
if fruit[tanghuru[end]] == 0:
kind += 1
fruit[tanghuru[end]] += 1
end += 1

if kind > 2:
fruit[tanghuru[start]] -= 1
if fruit[tanghuru[start]] == 0:
kind -= 1
start += 1


3 changes: 3 additions & 0 deletions tgyuuAn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,7 @@
| 65์ฐจ์‹œ | 2024.07.19 | ์ตœ์†Œ ๊ณตํ†ต ์กฐ์ƒ | <a href="https://www.acmicpc.net/problem/3584">๊ฐ€์žฅ ๊ฐ€๊นŒ์šด ๊ณตํ†ต ์กฐ์ƒ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/220
| 66์ฐจ์‹œ | 2024.07.22 | DP | <a href="https://www.acmicpc.net/problem/2169">๋กœ๋ด‡ ์กฐ์ข…ํ•˜๊ธฐ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/222
| 67์ฐจ์‹œ | 2024.07.26 | DP | <a href="https://www.acmicpc.net/problem/3687">์„ฑ๋ƒฅ๊ฐœ๋น„</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/223
| 68์ฐจ์‹œ | 2024.08.06 | ๊ทธ๋ฆฌ๋”” | <a href="https://www.acmicpc.net/problem/24337">๊ฐ€ํฌ์™€ ํƒ‘</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/226
| 69์ฐจ์‹œ | 2024.08.10 | ๋ˆ„์ ํ•ฉ, ์ˆ˜ํ•™ | <a href="https://www.acmicpc.net/problem/9527">1์˜ ๊ฐœ์ˆ˜ ์„ธ๊ธฐ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/228
| 70์ฐจ์‹œ | 2024.08.16 | ์Šคํƒ | <a href="https://www.acmicpc.net/problem/22866">ํƒ‘ ๋ณด๊ธฐ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/232
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import sys

def input(): return sys.stdin.readline().rstrip()

N, a, b = map(int, input().split())
if(N+1<(a+b)): print(-1)
else:
answer = [0 for _ in range(N)]

if a>b:
for idx, element in enumerate(range(N-a-b+1, N-b+1)):
answer[element] = idx+1

for idx, element in enumerate(range(N-1, N-b, -1)):
answer[element] = idx+1

for idx in range(N-a-b+1):
answer[idx] = 1

else:
for idx, element in enumerate(range(N-b, N)):
answer[element] = b - idx

for idx, element in enumerate(range(N-b-a+1, N-b)):
answer[element] = idx+1

for idx in range(N-b-a+1):
answer[idx] = 1

if a == 1:
answer[N-b], answer[0] = answer[0], answer[N-b]

print(*answer)
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import sys

def input(): return sys.stdin.readline().rstrip()

A, B = map(int, input().split())

bits = [0 for _ in range(len(bin(B)[2:]))]

for step in range(len(bits)):
one_count_per_bundle = (2**step)
total_count_bundle = 2 * (one_count_per_bundle)

B_d, B_m = divmod(B,total_count_bundle)
B_count = one_count_per_bundle * B_d
if(B_m >= one_count_per_bundle): B_count += min(one_count_per_bundle,(B_m - one_count_per_bundle + 1))

A_d, A_m = divmod(A-1,total_count_bundle)
A_count = one_count_per_bundle * A_d
if(A_m >= one_count_per_bundle): A_count += min(one_count_per_bundle, (A_m - one_count_per_bundle + 1))
bits[step] += (B_count - A_count)

print(sum(bits))
50 changes: 50 additions & 0 deletions tgyuuAn/์Šคํƒ/ํƒ‘ ๋ณด๊ธฐ.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import sys

def input(): return sys.stdin.readline().rstrip()

N = int(input())
building = list(map(int,input().split()))
answer_count = [0 for _ in range(N)]
answer_idx = [int(1e9) for _ in range(N)]
stack = []
for idx in range(N-1,-1,-1):
now_height = building[idx]
if len(stack) == 0: stack.append((now_height, idx))
else:
while stack and now_height >= stack[-1][0]:
stack.pop()

if len(stack) > 0:
if answer_idx[idx] != int(1e9) and abs(answer_idx[idx]-idx) < abs(stack[-1][1] - idx):
stack.append((now_height, idx))
continue

answer_idx[idx] = stack[-1][1]
answer_count[idx] += len(stack)

stack.append((now_height, idx))

stack = []
for idx in range(N):
now_height = building[idx]
if len(stack) == 0: stack.append((now_height, idx))
else:
while stack and now_height >= stack[-1][0]:
stack.pop()

if len(stack) > 0:
if answer_idx[idx] != int(1e9) and abs(answer_idx[idx]-idx) < abs(stack[-1][1] - idx):
answer_count[idx] += len(stack)
stack.append((now_height, idx))
continue

answer_idx[idx] = stack[-1][1]
answer_count[idx] += len(stack)

if stack and stack[-1][0] == now_height: continue

stack.append((now_height, idx))

for count, idx in zip(answer_count, answer_idx):
if idx == int(1e9): print(0)
else: print(count, idx+1)

0 comments on commit 2dd22df

Please sign in to comment.