diff --git a/ggangchongs/Angora/7days/BFS&DFS/Feb_1st_shortestPath.py b/ggangchongs/Angora/7days/BFS&DFS/Feb_1st_shortestPath.py new file mode 100644 index 0000000..370573d --- /dev/null +++ b/ggangchongs/Angora/7days/BFS&DFS/Feb_1st_shortestPath.py @@ -0,0 +1,31 @@ +from collections import deque + +def solution(maps): + queue = deque() + step = [(-1,0), (1,0), (0,-1), (0,1)] # 상 하 좌 우 + answer = bfs_maze(0,0, queue, step, maps) + if answer == 1: return -1 + else: return answer + +def bfs_maze(x,y, queue, step, maps): + n,m = len(maps), len(maps[0]) + queue.append((x,y)) + + while queue: + x, y = queue.popleft() + for act in step: + nx, ny = x + act[0], y + act[1] + + # 벗어나면 패스 + if nx < 0 or nx >= n or ny < 0 or ny >= m: 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[n-1][m-1] + +maps = [[1,0,1,1,1],[1,0,1,0,1],[1,0,1,1,1],[1,1,1,0,1],[0,0,0,0,1]] +print(solution(maps)) \ No newline at end of file diff --git a/ggangchongs/Angora/7days/Brute-Force/Feb_1st_Carpet.py b/ggangchongs/Angora/7days/Brute-Force/Feb_1st_Carpet.py new file mode 100644 index 0000000..9f153ef --- /dev/null +++ b/ggangchongs/Angora/7days/Brute-Force/Feb_1st_Carpet.py @@ -0,0 +1,6 @@ +def solution(brown, yellow): + + brown = (brown-4)/2 + for i in range(1, int(brown**1/2)+1): + if i*(brown-i) == yellow: + return [brown-i+2, i+2] \ No newline at end of file diff --git a/ggangchongs/Angora/7days/DP/Feb_1st_intTriangle.py b/ggangchongs/Angora/7days/DP/Feb_1st_intTriangle.py new file mode 100644 index 0000000..50fa479 --- /dev/null +++ b/ggangchongs/Angora/7days/DP/Feb_1st_intTriangle.py @@ -0,0 +1,12 @@ +def solution(triangle): + higher = triangle[0] + + for i in range(1, len(triangle)): + now = triangle[i] + for j in range(len(now)): + if j == 0: now[j] += higher[0] + elif j == len(now)-1: now[j] += higher[j-1] + else: now[j] += max(higher[j-1], higher[j]) + higher = now + + return max(higher) \ No newline at end of file diff --git a/ggangchongs/Angora/7days/Graph/Feb_1st_furthestNode.py b/ggangchongs/Angora/7days/Graph/Feb_1st_furthestNode.py new file mode 100644 index 0000000..afdf7ec --- /dev/null +++ b/ggangchongs/Angora/7days/Graph/Feb_1st_furthestNode.py @@ -0,0 +1,23 @@ +from collections import deque + +def solution(n, edge): + connect = [[] for _ in range(n+1)] + for a,b in edge: + connect[a].append(b) + connect[b].append(a) + + visited = [0]*(n+1) + visited[1] = 1 + queue = deque([1]) + while queue: + now = queue.popleft() + for next in connect[now]: + if not visited[next]: + visited[next] = visited[now] + 1 + queue.append(next) + + return visited.count(max(visited)) + +n = 6 +vertex = [[3, 6], [4, 3], [3, 2], [1, 3], [1, 2], [2, 4], [5, 2]] +print(solution(n, vertex)) \ No newline at end of file diff --git a/ggangchongs/Angora/7days/Greedy/Feb_1st_lifeBoat.py b/ggangchongs/Angora/7days/Greedy/Feb_1st_lifeBoat.py new file mode 100644 index 0000000..62e60d9 --- /dev/null +++ b/ggangchongs/Angora/7days/Greedy/Feb_1st_lifeBoat.py @@ -0,0 +1,24 @@ +def solution(people, limit): + people = sorted(people, reverse=True) + i,j = 0, len(people)-1 + answer = 0 + + while i < j: + tmp = people[i] + people[j] + if tmp <= limit: + while tmp + people[j-1] <= limit: + tmp += people[j-1] + j -= 1 + i += 1 + j -= 1 + answer += 1 + else: + i += 1 + answer += 1 + if i == j: answer += 1 + + return answer + +people = [70, 50, 50, 10, 20] +limit = 100 +print(solution(people, limit)) \ No newline at end of file diff --git a/ggangchongs/Angora/7days/Hash/Feb_1st_Camouflage.py b/ggangchongs/Angora/7days/Hash/Feb_1st_Camouflage.py new file mode 100644 index 0000000..84c47d5 --- /dev/null +++ b/ggangchongs/Angora/7days/Hash/Feb_1st_Camouflage.py @@ -0,0 +1,17 @@ +def solution(clothes): + + type = {} + for cloth in clothes: + answer = 1 + if cloth[1] not in type: + type[cloth[1]] = 1 + else: + type[cloth[1]] += 1 + + for c in type.values(): + answer *= c+1 + return answer-1 + + +clothes = [["yellow_hat", "headgear"], ["blue_sunglasses", "eyewear"], ["green_turban", "headgear"]] +print(solution(clothes)) \ No newline at end of file diff --git a/ggangchongs/Angora/7days/Stack&Queue/Feb_1st_Printer.py b/ggangchongs/Angora/7days/Stack&Queue/Feb_1st_Printer.py new file mode 100644 index 0000000..738448e --- /dev/null +++ b/ggangchongs/Angora/7days/Stack&Queue/Feb_1st_Printer.py @@ -0,0 +1,24 @@ +def solution(priorities, location): + answer = 0 + + while len(priorities) != 0: + tmp = priorities.pop(0) + + if len(priorities) == 0: + return answer + 1 + + if tmp < max(priorities): # 출력 불가 + priorities.append(tmp) + if location == 0: location = len(priorities)-1 + else: location -= 1 + else: # 출력 가능 + answer += 1 + if location == 0: return answer + else: location -= 1 + +priorities = [1, 1, 2, 3, 2, 1] +location = 0 +print(solution(priorities, location)) + + +tmp = [] \ No newline at end of file diff --git a/ggangchongs/Angora/FromRestaurant/DP/11055.py b/ggangchongs/Angora/FromRestaurant/DP/11055.py index 6a67e7f..17a4f06 100644 --- a/ggangchongs/Angora/FromRestaurant/DP/11055.py +++ b/ggangchongs/Angora/FromRestaurant/DP/11055.py @@ -4,7 +4,7 @@ sequence = list(map(int, sys.stdin.readline().split())) dp = [0]*n -dp[0], maxSum = sequence[0], sequence[0] +dp[0] = sequence[0] for i in range(1,n): for j in range(i): @@ -12,6 +12,5 @@ dp[i] = max(dp[i], dp[j] + sequence[i]) else: dp[i] = max(dp[i], sequence[i]) - maxSum = max(maxSum, dp[i]) -print(maxSum) +print(max(dp)) diff --git a/ggangchongs/Angora/FromRestaurant/Greedy/1339.py b/ggangchongs/Angora/FromRestaurant/Greedy/1339.py index 9f55298..7763a28 100644 --- a/ggangchongs/Angora/FromRestaurant/Greedy/1339.py +++ b/ggangchongs/Angora/FromRestaurant/Greedy/1339.py @@ -1,17 +1,13 @@ n = int(input()) -voca = [] alpha = {} for i in range(n): - tmp = list(input()) - for t in tmp: - alpha[t] = 0 - voca.append(tmp) - -for v in voca: - length = len(v) + voca = list(input()) + length = len(voca) for i in range(length): - oldValue = alpha[v[i]] - alpha[v[i]] += 10**(length-(i+1)) + if voca[i] not in alpha: + alpha[voca[i]] = 10**(length-(i+1)) + else: + alpha[voca[i]] += 10**(length-(i+1)) sorted_alpha = sorted(alpha.items(), key = lambda item: -item[1]) start = 9 diff --git a/ggangchongs/Angora/FromRestaurant/dataStructure_tmp/11866.py b/ggangchongs/Angora/FromRestaurant/dataStructure_tmp/11866.py new file mode 100644 index 0000000..1d9e60d --- /dev/null +++ b/ggangchongs/Angora/FromRestaurant/dataStructure_tmp/11866.py @@ -0,0 +1,24 @@ +import sys + +n, k = map(int, sys.stdin.readline().split()) + +queue = [] +for i in range(n): + queue.append(i+1) + +count = 1 +answer = [] +while len(queue) != 0: + if count != k: + tmp = queue.pop(0) + queue.append(tmp) + count += 1 + else: + answer.append(queue.pop(0)) + count = 1 + +print("<", end='') +for i,a in enumerate(answer): + if i == len(answer)-1: print(a, end='') + else: print(a, end=', ') +print(">", end='') \ No newline at end of file diff --git a/ggangchongs/Angora/FromRestaurant/dataStructure_tmp/1715.py b/ggangchongs/Angora/FromRestaurant/dataStructure_tmp/1715.py new file mode 100644 index 0000000..48a64db --- /dev/null +++ b/ggangchongs/Angora/FromRestaurant/dataStructure_tmp/1715.py @@ -0,0 +1,16 @@ +import sys +import heapq + +n = int(sys.stdin.readline()) +heap = [] +for i in range(n): heapq.heappush(heap, int(sys.stdin.readline())) + +answer = 0 +while len(heap)>=2: + first = heapq.heappop(heap) + second = heapq.heappop(heap) + answer += first + second + if len(heap) == 0: break + else: heapq.heappush(heap, first + second) + +print(answer) \ No newline at end of file diff --git a/ggangchongs/Angora/FromRestaurant/dataStructure_tmp/1764.py b/ggangchongs/Angora/FromRestaurant/dataStructure_tmp/1764.py new file mode 100644 index 0000000..5a98f65 --- /dev/null +++ b/ggangchongs/Angora/FromRestaurant/dataStructure_tmp/1764.py @@ -0,0 +1,13 @@ +import sys + +n, m = map(int, sys.stdin.readline().split()) + +d = [] +for i in range(n): d.append(sys.stdin.readline()) +b = [] +for i in range(m): b.append(sys.stdin.readline()) + +db = sorted(list(set(d)&set(b))) +print(len(db)) +for name in db: + print(name, end='') \ No newline at end of file diff --git a/ggangchongs/Angora/FromRestaurant/dataStructure_tmp/1874.py b/ggangchongs/Angora/FromRestaurant/dataStructure_tmp/1874.py new file mode 100644 index 0000000..30db132 --- /dev/null +++ b/ggangchongs/Angora/FromRestaurant/dataStructure_tmp/1874.py @@ -0,0 +1,31 @@ +''' +1 2 3 4 -> 4 +1 2 3 -> 4 +1 2 -> 4 3 +1 2 5 6 -> 4 3 +1 2 5 -> 4 3 6 +1 2 5 7 8 -> 4 3 6 + -> 4 3 6 8 7 5 2 1 +''' + +import sys + +n = int(sys.stdin.readline()) + +candi = 1 +stack, answer = [], [] +correct = True +for i in range(n): + target = int(sys.stdin.readline()) + while candi <= target: + stack.append(candi) + answer.append("+") + candi += 1 + if stack[-1] == target: + stack.pop() + answer.append("-") + else: correct = False; break + +if correct == False: print("NO") +else: + for a in answer: print(a) diff --git a/ggangchongs/Angora/FromRestaurant/dataStructure_tmp/2493.py b/ggangchongs/Angora/FromRestaurant/dataStructure_tmp/2493.py new file mode 100644 index 0000000..d626dd4 --- /dev/null +++ b/ggangchongs/Angora/FromRestaurant/dataStructure_tmp/2493.py @@ -0,0 +1,18 @@ +import sys + +n = int(sys.stdin.readline()) +topList = list(map(int, sys.stdin.readline().split())) + +indexStack, answer = [1],[0] +for i, top in enumerate(topList): + if i == 0: continue + else: + + while topList[indexStack[-1]-1] < top: + indexStack.pop() + if len(indexStack) == 0: break + if len(indexStack) == 0: answer.append(0) + else: answer.append(indexStack[-1]) + indexStack.append(i+1) + +for i in answer: print(i, end=' ') \ No newline at end of file diff --git a/ggangchongs/Angora/FromRestaurant/dataStructure_tmp/27160.py b/ggangchongs/Angora/FromRestaurant/dataStructure_tmp/27160.py new file mode 100644 index 0000000..ff26639 --- /dev/null +++ b/ggangchongs/Angora/FromRestaurant/dataStructure_tmp/27160.py @@ -0,0 +1,15 @@ +import sys + +n = int(sys.stdin.readline()) + +fruits = {} +for i in range(n): + tmp, num = sys.stdin.readline().split() + if tmp in fruits: + fruits[tmp] += int(num) + else: + fruits[tmp] = int(num) + +if 5 in fruits.values(): print("YES") +else: print("NO") + \ No newline at end of file diff --git a/ggangchongs/Angora/FromRestaurant/dataStructure_tmp/2841.py b/ggangchongs/Angora/FromRestaurant/dataStructure_tmp/2841.py new file mode 100644 index 0000000..f94affd --- /dev/null +++ b/ggangchongs/Angora/FromRestaurant/dataStructure_tmp/2841.py @@ -0,0 +1,30 @@ +import sys + +n, p = map(int, sys.stdin.readline().split()) +answer = 0 + +guitar = {} +line = 0 +for i in range(n): + newLine, newP = map(int, sys.stdin.readline().split()) + + + if line != newLine and newLine not in guitar: + tmp = [newP] + guitar[newLine] = tmp + answer += 1 + elif (line != newLine and newLine in guitar) or line == newLine: + tmp = guitar[newLine] + while tmp[-1] > newP: + tmp.pop(); answer += 1 + if len(tmp) == 0: break + if len(tmp) == 0: + tmp.append(newP) + answer += 1 + elif tmp[-1] < newP: + tmp.append(newP) + answer += 1 + + line = newLine + +print(answer) \ No newline at end of file diff --git a/ggangchongs/Angora/FromRestaurant/dataStructure_tmp/9012.py b/ggangchongs/Angora/FromRestaurant/dataStructure_tmp/9012.py new file mode 100644 index 0000000..1fa9a01 --- /dev/null +++ b/ggangchongs/Angora/FromRestaurant/dataStructure_tmp/9012.py @@ -0,0 +1,17 @@ +import sys + +t = int(sys.stdin.readline()) + +testStack = [] +answer = "YES" +for i in range(t): + tmpPS = list(sys.stdin.readline()) + + for p in tmpPS: + if p == '(': testStack.append(p) + if p == ')': + if testStack[-1:] == ['(']: testStack.pop() + else: answer = "NO"; break + if len(testStack) != 0: answer = "NO" + print(answer) + testStack.clear(); answer ="YES"