Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[23-03-16] jamin.py #175

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
0adeada
Create [스택-큐] 다리를 지나는 트럭 seungyeon.py:
seungueonn Mar 9, 2023
cd10e99
Create [스택-큐] 다리를 지나는 트럭 hyuksoon.py
chs0412 Mar 9, 2023
e337ab6
Create [완전탐색] 피로도 hyuksoon.py
chs0412 Mar 9, 2023
d7115ff
Create [스택-큐] 주식가격 hyuksoon.py
chs0412 Mar 9, 2023
a0eb839
Create [완전탐색] 전력망을 둘로 나누기 hyuksoon.py
chs0412 Mar 9, 2023
61f8f6c
Create [스택-큐] 주식가격 seungyeon.py
seungueonn Mar 9, 2023
67d2fa7
Create [완전탐색] 피로도 seungyeon.py
seungueonn Mar 9, 2023
1e2263c
Create [그리디] 단속카메라 hyuksoon.py
chs0412 Mar 9, 2023
44b9d63
Create [그리디] 카메라 seungyeon.py
seungueonn Mar 9, 2023
221d59d
Create 다리를 지나는 트럭 kyuhyun.py
lalabulla Mar 9, 2023
43ef6f9
Create 피로도 kyuhyun.py
lalabulla Mar 9, 2023
3bec8c1
Create kyuhyun.py
lalabulla Mar 9, 2023
318c6ac
Create 전력망을 둘로 나누기 kyuhyun.py
lalabulla Mar 9, 2023
5973d63
Create 단속카메라 kyuhyun.py
lalabulla Mar 9, 2023
3a872b8
Create [완전탐색] 전력망을 둘로 나누기 seungyeon.py
seungueonn Mar 9, 2023
26fd32c
Merge pull request #159 from da-in/dain
da-in Mar 10, 2023
f373ed6
Merge pull request #160 from chs98412/main
chs98412 Mar 10, 2023
1dcfee4
Merge pull request #162 from seungyeonnnnnni/main
seungueonn Mar 10, 2023
798c5a8
Merge pull request #161 from lalabulla/main
lalabulla Mar 10, 2023
695cbc2
Update CODEOWNERS
da-in Mar 12, 2023
224b678
Create [DP] 사칙연산 hyuksoon.py #163
chs0412 Mar 13, 2023
080ea0c
[DFS-BFS] 단어변환 hyuksoon.py #164
chs0412 Mar 13, 2023
17c7659
Create 사칙연산 kyuhyun.py #163
lalabulla Mar 13, 2023
aedf6cd
Create 단어 변환 kyuhyun.py #164
lalabulla Mar 13, 2023
8379f99
Create [DFS-BFS] 단어변환 seungyeon.py
seungueonn Mar 13, 2023
97f70b6
create [DP] 사칙연산 seungyeon.py
seungueonn Mar 13, 2023
4106f9a
Merge pull request #167 from lalabulla/main
lalabulla Mar 14, 2023
b9ff2fd
Merge pull request #166 from chs98412/main
chs98412 Mar 14, 2023
8ac867e
Merge pull request #168 from seungyeonnnnnni/main
seungueonn Mar 15, 2023
6be7452
Update README.md
lalabulla Mar 16, 2023
4df879a
Merge pull request #165 from da-in/dain
da-in Mar 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @da-in @Lee-DoHa @lalabulla @seungyeonnnnnni @chs98412
* @da-in @Lee-DoHa @lalabulla @seungyeonnnnnni @chs98412 @jaminleee
28 changes: 28 additions & 0 deletions Programmers - 고득점 Kit/[DFS-BFS] 단어 변환/kyuhyun.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
def solution(begin, target, words):
visit = [0] * len(words)
st = []
answer = -1
leng = len(begin)

if target not in words:
return 0

st.append(begin)
while st:
wd = st.pop()
answer += 1

if wd == target :
return answer

for k in range(len(words)):
word = words[k]
count = 0
if visit[k] == 1:
continue
for i in range(leng):
if wd[i] == word[i]:
count += 1
if count == leng - 1:
st.append(word)
visit[k] = 1
26 changes: 26 additions & 0 deletions Programmers - 고득점 Kit/[DFS-BFS] 단어변환/hyuksoon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from collections import deque
def solution(begin, target, words):
answer = 0

def find(word,cnt):

for idx,w in enumerate(words):
if not visit[idx]:
ck=0
for i in range(len(w)):
if w[i]!=word[i]:
ck+=1
if ck==1:
visit[idx]=True
q.append([w,cnt+1])

q=deque()
q.append([begin,0])
visit=[False]*(len(words))
while q:
word,cnt=q.popleft()
if word==target:
return cnt
find(word,cnt)

return answer
34 changes: 34 additions & 0 deletions Programmers - 고득점 Kit/[DFS-BFS] 단어변환/seungyeon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from collections import deque


def main():
print(solution("hit","cog",["hot", "dot", "dog", "lot", "log"]))

def solution(begin, target, words):
answer = 0
q = deque()
q.append([begin, 0])
v = [ 0 for i in range(len(words))]

while q:
word, cnt = q.popleft()

if word == target:
answer = cnt
break

for i in range(len(words)):
cnt = 0
if not V[i]:
for j in range(len(word)):
if word[j] != words[i][j]:
cnt += 1
if cnt == 1:
q.append([words[i], cnt+1])
v[i] = 1

return answer


if __name__ == "__main__":
main()
3 changes: 3 additions & 0 deletions Programmers - 고득점 Kit/[DP] 사칙연산/hyuksoon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'''
인터넷에 찾아봤는데도 이해를 잘 못하겠는 관계로 추후 제대로 풀고 업데이트 하겠음....
'''
37 changes: 37 additions & 0 deletions Programmers - 고득점 Kit/[DP] 사칙연산/kyuhyun.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
def solution(arr):
n = len(arr)
dp_max = [[0 for _ in range(n)] for _ in range(n)]
dp_min = [[1001 for _ in range(n)] for _ in range(n)]

# 숫자 담는 배열
num = []
# 기호 담는 배열
log = []

for i in range(len(arr)):
if i % 2 == 0:
num.append(int(arr[i]))
else:
log.append(arr[i])

# 숫자가 1개면 step = 0, 숫자가 두개면 step = 1, ...
for step in range(n):
# step에 따라 만들수 있는 숫자 조합
for i in range(n - step):

j = i + step

if step == 0:
dp_max[i][i] = num[i]
dp_min[i][i] = num[i]
else:
# i 부터 j번째 수까지 괄호 하나씩 늘리면서 계산
for k in range(i, j):
if log[k] == '+' :
dp_max[i][j] = max(dp_max[i][j], dp_max[i][k] + dp_max[k+1][j]) # 더하기의 최대
dp_min[i][j] = min(dp_min[i][j], dp_min[i][k] + dp_min[k+1][j]) # 더하기의 최소
else:
dp_max[i][j] = max(dp_max[i][j], dp_max[i][k] - dp_min[k+1][j]) # 빼기의 최대
dp_min[i][j] = min(dp_min[i][j], dp_min[i][k] - dp_max[k+1][j]) # 빼기의 최소

return dp_max[0][n-1]
25 changes: 25 additions & 0 deletions Programmers - 고득점 Kit/[DP] 사칙연산/seungyeon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
def main():
print(solution(["5", "-", "3", "+", "1", "+", "2", "-", "4"]))

def solution(arr):
minmax = [0, 0]
sum_value = 0
for idx in range(len(arr)-1, -1, -1):
if arr[idx] == '+':
continue
elif arr[idx] == '-':
tempmin, tempmax = minmax
minmax[0] = min(-(sum_value + tempmax), -sum_value+tempmin)

minus_v = int(arr[idx+1])
minmax[1] = max(-(sum_value+tempmin), -minus_v+(sum_value-minus_v)+tempmax)

sum_value = 0
elif int(arr[idx]) >= 0:
sum_value += int(arr[idx])
minmax[1] += sum_value
return minmax[1]


if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def solution(routes):
answer = 1
routes.sort(key=lambda x: x[1])
cam=routes[0][1]
for r in routes[1:]:
if r[0]>cam:
cam=r[1]
answer+=1
return answer
12 changes: 12 additions & 0 deletions Programmers - 고득점 Kit/[그리디] 단속카메라/kyuhyun.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def solution(routes):
routes.sort(key=lambda x: x[1])

camera = 0
last_loc = -30000

for start, end in routes:
if start > last_loc:
camera += 1
last_loc = end

return camera
18 changes: 18 additions & 0 deletions Programmers - 고득점 Kit/[그리디] 카메라/seungyeon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
def main():
print(solution([[-20,-15], [-14,-5], [-18,-13], [-5,-3]]))

def solution(routes):
answer = 0
routes.sort(key=lambda x : x[1])
camera=[routes[0][1]]
for i in range(1,len(routes)):
if routes[i][0] <= camera[-1] and routes[i][1] >= camera[-1]:
continue
else:
camera.append(routes[i][1])
return len(camera)



if __name__ == "__main__":
main()
17 changes: 17 additions & 0 deletions Programmers - 고득점 Kit/[스택-큐] 주식가격/kyuhyun.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from collections import deque
def solution(prices):
answer = []
prices = deque(prices)
while prices:
cur_price = prices.popleft()

count = 0

for i in prices:
if cur_price > i:
count += 1
break
count += 1

answer.append(count)
return answer
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from collections import deque
def solution(bridge_length, weight, truck_weights):
answer = 0
truck_weights=truck_weights[::-1]
q=deque()

restW=weight
while truck_weights:
answer+=1
if q and answer-q[-1][1]>=bridge_length:
restW+=q.pop()[0]
target=truck_weights.pop()
if target<=restW:
q.appendleft([target,answer])
restW-=target
else:
while target>restW:
temp=q.pop()
restW+=temp[0]
answer+=bridge_length- (answer-temp[1])
q.appendleft([target,answer])
restW-=target



return answer+bridge_length
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from collections import deque
def solution(bridge_length, weight, truck_weights):

total_time = 0
sum_weight = 0
truck_weights = deque(truck_weights)
bridge = deque([0] * bridge_length)

while bridge:

total_time += 1
sum_weight -= bridge[0]
bridge.popleft()

if truck_weights:
if sum_weight + truck_weights[0] <= weight:
sum_weight += truck_weights[0]
bridge.append(truck_weights.popleft())
else:
bridge.append(0)

return total_time
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
def main():
print(solution(2,10,[7,4,5,6]))

def solution(bridge_length, weight, truck_weights):

answer = 0
que = [0 for _ in range(bridge_length)]

while que:

answer += 1
que.pop(0)

if truck_weights:
if sum(que) + truck_weights[0] <= weight:
t = truck_weights.pop(0)
que.append(t)
else:
que.append(0)


return answer

# def solution(bridge_length, weight, truck_weights):
# answer = 0
# que = []
# i=total=0
# que.append(truck_weights[0])
# while(que and i < len(truck_weights)):
# que.append(truck_weights[i])
# total += truck_weights[i]

# answer+=1
# if len(que) == bridge_length and total <= weight:
# que.clear
# i+=1
# # que.append(truck_weights[i])
# answer+=1

# return answer

if __name__ == "__main__":
main()
12 changes: 12 additions & 0 deletions Programmers - 고득점 Kit/[스택-큐] 주식가격/hyuksoon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def solution(prices):
answer = []
for i in range(len(prices)):
k = True
for j in range(i, len(prices)):
if prices[i] > prices[j]:
answer.append(j-i)
k = False
break
if k:
answer.append(len(prices)-i-1)
return answer
14 changes: 14 additions & 0 deletions Programmers - 고득점 Kit/[스택-큐] 주식가격/seungyeon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
def main():
print(solution([1, 2, 3, 2, 3]))

def solution(prices):
answer = [0] * len(prices)
for i in range(len(prices)):
for j in range(i+1,len(prices)):
answer[i] += 1
if prices[i] > prices[j]: break

return answer

if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# import sys
# sys.setrecursionlimit(10000)
def solution(n, wires):
answer = 100

data=[[]for i in range(n+1)]
for w in wires:
data[w[0]].append(w[1])
data[w[1]].append(w[0])


def find(tar,ex,visit):
count=0
visit[tar]=True
for i in data[tar]:
if i==ex:
continue
if not visit[i]:
count+=1
count+=find(i,ex,visit)
return count

for w in wires:
visit=[False]*(n+1)
visit[w[0]]=True
visit[w[1]]=True

a=find(w[0],w[1],visit)
b=find(w[1],w[0],visit)

answer=min(answer,abs(a-b))

return answer
Loading