본문 바로가기

permutation3

[Python] 15686. 치킨 배달 https://www.acmicpc.net/problem/15686 15686번: 치킨 배달 크기가 N×N인 도시가 있다. 도시는 1×1크기의 칸으로 나누어져 있다. 도시의 각 칸은 빈 칸, 치킨집, 집 중 하나이다. 도시의 칸은 (r, c)와 같은 형태로 나타내고, r행 c열 또는 위에서부터 r번째 칸 www.acmicpc.net 순열로 완전탐색하여 도시 치킨거리를 구한다. def next_perm(a): i = len(a)-1 while i > 0 and a[i-1] >= a[i]: i -= 1 if i = a[j]: j -= 1 a[i-1], a[j] = a[j], a[i-1] j = len(a)-1 while i < j: a[i], a[j] = a[j], a[i] i += 1 j -= 1 retu.. 2021. 4. 8.
[Python] 6.4. Triangle https://app.codility.com/demo/results/trainingX6JCFR-MQJ/ Test results - Codility An array A consisting of N integers is given. A triplet (P, Q, R) is triangular if 0 ≤ P A[R], A[Q] + A[R] > A[P], A[R] + A[P] > A[Q]. For example, consider array A such that: A[0] = 10 A[1] = 2 A[2] = 5 A[3] = 1 A[4] = 8 A app.codility.com 인풋 데이터의 사이즈가 10만 아래이기 때문에 완전탐색하기로 결정하였다. 순열을.. 2021. 3. 26.
[Python]14889. 스타트와 링크 https://www.acmicpc.net/problem/14889 14889번: 스타트와 링크 예제 2의 경우에 (1, 3, 6), (2, 4, 5)로 팀을 나누면 되고, 예제 3의 경우에는 (1, 2, 4, 5), (3, 6, 7, 8)로 팀을 나누면 된다. www.acmicpc.net 이 문제는 0*n//2 와 1*n//2 로 이루어진 n 길이의 순열을 만들어서 이중포문에 넣으면 되는 간단한 문제이다. 12345678910111213141516171819202122232425262728293031323334353637383940414243def next_perm(a): i = len(a)-1 while i > 0 and a[i-1] >= a[i]: i -= 1 if i = a[j]: j -= 1 a.. 2019. 4. 22.
728x90
반응형