Greedy5 [python] 섬 연결하기 문제 출처 섬 연결하기 풀이 def solution(n, costs): answer = 0 costs.sort(key=lambda x: x[2]) visited = [0] * n visited[0] = 1 while sum(visited) != n: for cost in costs: s, e, c = cost if visited[s] or visited[e]: if visited[s] and visited[e]: continue else: visited[s] = 1 visited[e] = 1 answer += c break return answer 2019. 10. 14. [python] 단속카메라 문제 출처 단속카메라 풀이 def solution(routes): answer = [] routes.sort(key=lambda x: (x[0], x[1])) _, move_out = routes[0] for i in range(1, len(routes)): if routes[i][0] > move_out: answer.append(i) _, move_out = routes[i] else: move_out = min(routes[i][1], move_out) if answer[-1] != len(routes): return len(answer)+1 return len(answer) 2019. 10. 14. [python] 1541. 잃어버린 괄호 문제 출처 1541. 잃어버린 괄호 풀이 exps = input().split('-') result = 0 for i in range(len(exps)): sum_ = sum(list(map(int, exps[i].split('+')))) if i == 0: result += sum_ else: result -= sum_ print(result) 2019. 9. 29. [python] 2217. 로프 문제 출처 2217. 로프 풀이 N = int(input()) ropes = [int(input()) for _ in range(N)] ropes.sort() max_ = 0 for i in range(N): max_ = max((N-i) * ropes[i], max_) print(max_) 2019. 9. 29. 이전 1 2 다음