알고리즘
-
알고리즘 & 자료구조 스터디(10조) 2일차알고리즘 2023. 5. 23. 20:57
Q1011 달나라 여행 이게 왜 안되는지는 의문이여서 구글링 좀 참고했지만 내가 왜 안됬는지 모르기 때문에 나중에 물어봐야지 def spaceShip(x, y): distance = y - x try: if distance == 1: return 1 elif distance == 2: return 2 elif distance == 3: return 3 else: raise Exception("") except Exception: num1 = distance ** (1/2) num2 = int(distance ** (1/2)) if num1 == num2: return num2 + (num2 -1) # (distance * 2) - 1 else: num3 = 0 for i in range(1, num2 +..
-
알고리즘 & 자료구조 스터디(10조) 1일차알고리즘 2023. 5. 23. 15:09
Q.4948 베르트랑 공준 - 소수인지 아닌지를 구하는 함수를 적용시켜서 구해보았지만 정답이 아니다 수정을 좀 더 진행 한 후 안되면 어쩔 수 없지... def sosu(x): for i in range(2, x): if x % i == 0: return False return True x = int(input()) count = 0 for i in range(x, (2 * x) + 1): if sosu(i): count += 1 print(count) Q.2869 달팽이는 올라가고 싶다 - 시간초과라고 하는데 줄여봐야겠다. 반복문 아니라 다른 것을 이용하는 지 고민이 된다. x, y, z = map(int, input().split()) start = 0 count = 0 while True: star..