본문 바로가기
728x90
반응형

전체 글110

[Codility] Lesson16 - Greedy algorithms: Max Nonoverlapping Segments Problem Located on a line are N segments, numbered from 0 to N − 1, whose positions are given in arrays A and B. For each I (0 ≤ I < N) the position of segment I is from A[I] to B[I] (inclusive). The segments are sorted by their ends, which means that B[K] ≤ B[K + 1] for K such that 0 ≤ K < N − 1. Two segments I and J, such that I ≠ J, are overlapping if they share at least one common point. In .. 2021. 2. 10.
[Codility] Lesson12 - Euclidean algorithm: Common Prime Divisors Problem A prime is a positive integer X that has exactly two distinct divisors: 1 and X. The first few prime integers are 2, 3, 5, 7, 11 and 13. A prime D is called a prime divisor of a positive integer P if there exists a positive integer K such that D * K = P. For example, 2 and 5 are prime divisors of 20. You are given two positive integers N and M. The goal is to check whether the sets of pr.. 2021. 2. 9.
[Codility] Lesson12 - euclidean algorithm: Chocolates By Numbers Problem Two positive integers N and M are given. Integer N represents the number of chocolates arranged in a circle, numbered from 0 to N − 1. You start to eat the chocolates. After eating a chocolate you leave only a wrapper. You begin with eating chocolate number 0. Then you omit the next M − 1 chocolates or wrappers on the circle, and eat the following one. More precisely, if you ate chocolat.. 2021. 2. 8.
[Codility] Lesson10 - Prime and composite numbers: MinPerimeterRectangle Problem n integer N is given, representing the area of some rectangle. The area of a rectangle whose sides are of length A and B is A * B, and the perimeter is 2 * (A + B). The goal is to find the minimal perimeter of any rectangle whose area equals N. The sides of this rectangle should be only integers. For example, given integer N = 30, rectangles of area 30 are: (1, 30), with a perimeter of 6.. 2021. 1. 30.
728x90
반응형