문제 링크 10205번: 헤라클레스와 히드라 헤라클레스는 그리스 신화의 유명한 비극적인 영웅이다. 그는 제우스의 사생아로 태어났는데, 이때문에 제우스의 아내 헤라는 그를 매우 싫어했다. 그는 매우 강한 힘과 높은 지식을 가졌지만, www.acmicpc.net 문제 풀이 머리의 수가 h로 주어지고, 문자열이 주어질 때, 문자열 중 문자가 c일 경우 머리를 자르고 2개가 다시 자라나므로 h + 1이 되고, 문자가 b일 경우에는 다시 자라나지 않으므로 h - 1이 된다. 이 규칙으로 반복문을 구현했다. 정답 코드 for n in range(1, int(input()) + 1) : h = int(input()) for i in input() : if i == "c" : h += 1 else : h -= 1 pr..
문제 링크 10187번: Golden There are many special irrational numbers in nature. One is the “golden ratio” represented by the Greek letter phi, φ, which has a value of φ = (1 + √5) / 2 = 1.61803399..... Given 2 real numbers, determine whether their ratio is equal (or close to www.acmicpc.net 문제 풀이 주어진 황금비율과 1%의 오차 범위 내에 입력값이 해당된다면, "golden"을 출력하고, 아니라면 "not"을 출력한다. 정답 코드 gold = 1.61803399 dif = gold * ..
문제 링크 10185번: Focus There is no longer a STAAR test in physics—the pressure is off! You can just learn physics for the sheer fun of learning about the natural world (and to prepare for college)! To celebrate this fact, here’s a program on lenses. Lenses use refraction of www.acmicpc.net 문제 풀이 문제에 주어진 1/f = 1/p + 1/q를 통해 f를 구해주어야 한다. 이 식을 통해 f를 구해주면 f = pq / (p + q)이다. 정답 코드 for _ in range(int(in..
문제 링크 10180번: Ship Selection Input begins with a line with one integer T (1 ≤ T ≤ 50) denoting the number of test cases. Each test case begins with a line with two space-separated integers N and D, where N (1 ≤ N ≤ 100) denotes the number of ships in the docking bay and D (1 www.acmicpc.net 정답 코드 for _ in range(int(input())) : N, D = map(int, input().split()) cnt = 0 for _ in range(N) : V, F, C ..
문제 링크 10178번: 할로윈의 사탕 할로윈데이에 한신이네는 아부지가 사탕을 나눠주신다. 하지만 한신이의 형제들은 서로 사이가 좋지않아 서른이 넘어서도 사탕을 공정하게 나누어 주지 않으면 서로 싸움이 난다. 매년 할로윈 www.acmicpc.net 문제 풀이 주어진 규칙에 따라 답을 출력해준다. c와 v에 대한 몫과 나머지를 구해준다. 정답 코드 for _ in range(int(input())) : c, v = map(int, input().split()) print("You get {:d} piece(s) and your dad gets {:d} piece(s).".format(c // v, c % v))
문제 링크 9950번: Rectangles Input is a series of lines, each containing 3 integers, l, w, and a ( 0 ≤ l w ≤100, 0 ≤ a ≤ 10,000) representing the length, width and area of a rectangle in that order. The integers are separated by a single space. In each row, only one of the val www.acmicpc.net 문제 풀이 입력값에 0의 위치에 따른 빈칸의 값을 채워 출력해준다. 정답 코드 while True : a, b, c = map(int, input().split()) if a == b == c =..
문제 링크 9945번: Centroid of Point Masses Input will be sets of points. Each set will be specified by the number of points n in the set followed by n lines of three numbers representing xi, yi, and mi values for i = 1 to n. All these numbers will be integers from 1 to 5000. That is, n will be from www.acmicpc.net 문제 풀이 무게 중심을 구해주기 위해 xi * m의 합을 m의 합으로 나누어주었다. 정답 코드 cnt = 1 while True : N = int(input..
문제 링크 9924번: The Euclidean Algorithm The famous Euclidean algorithm is found in Book VII of the Elements. The Elements was written in 300 B.C.~by the Greek mathematician Euclid. It is rumored that King Ptolemy, having looked through the Elements, hopefully asked Euclid if there were not a sho www.acmicpc.net 문제 풀이 A, B가 주어졌을 때, 특정한 계산을 통해 B가 0이 될 때 까지의 반복문 수행 횟수를 구해준다. 정답 코드 def solve(A, B, n) :..