본문 바로가기

Python78

[Python] 16235. 나무 재테크 www.acmicpc.net/problem/16235 16235번: 나무 재테크 부동산 투자로 억대의 돈을 번 상도는 최근 N×N 크기의 땅을 구매했다. 상도는 손쉬운 땅 관리를 위해 땅을 1×1 크기의 칸으로 나누어 놓았다. 각각의 칸은 (r, c)로 나타내며, r은 가장 위에서부터 www.acmicpc.net 시간초과 (0%) def spring(x,y,z): if ground[x][y] < z: z = -z #사망 else: ground[x][y] -= z z += 1 return x,y,z def summer(x,y,z): if z < 0: ground[x][y] += abs(z)//2 def fall(x,y,z): global N child = [] for i in range(len(direct.. 2021. 4. 15.
[Python] 14503. 로봇 청소기 https://www.acmicpc.net/problem/14503 14503번: 로봇 청소기 로봇 청소기가 주어졌을 때, 청소하는 영역의 개수를 구하는 프로그램을 작성하시오. 로봇 청소기가 있는 장소는 N×M 크기의 직사각형으로 나타낼 수 있으며, 1×1크기의 정사각형 칸으로 나누어 www.acmicpc.net 문제 조건에 첫행,끝행,첫열,끝열은 모두 벽으로 막혀있다고 했으므로 next_r과 next_c가 이동할 수 있는지 확인할 필요 없다. 문제를 잘 읽어보면 알고리즘 구현의 힌트를 찾을 수 있다. di = ((-1,0),(0,1),(1,0),(0,-1)) N, M = map(int, input().split()) r, c, d = map(int, input().split()) MAP = [list(.. 2021. 4. 14.
[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] Leader https://codility.com/media/train/6-Leader.pdf Leader는 크기 N인 배열A 에서 과반수 이상 (N//2+1) 의 갯수를 가지고 있는 요소를 말한다. Leader를 조사하는 방법을 아래와 같이 정리하였다. 1. Sorting 정렬 후 중앙값의 카운트를 계산한다. 카운트가 n//2 보다 크다면 Leader에 해당한다. Detected time complexity O(N * log(N)) def solution(A): n = len(A) s_A = sorted(A) leader = None count = 0 for i in range(n): if s_A[i] == s_A[n//2]: count += 1 if count > n // 2: leader = s_A[n//2] .. 2021. 4. 5.
[Python] 8.1. Dominator https://app.codility.com/demo/results/trainingKJKX8S-C3B/ Test results - Codility An array A consisting of N integers is given. The dominator of array A is the value that occurs in more than half of the elements of A. For example, consider array A such that A[0] = 3 A[1] = 4 A[2] = 3 A[3] = 2 A[4] = 3 A[5] = -1 A[6] = 3 A[7] = 3 The dom app.codility.com Task Score 100% Correctness 100% Performan.. 2021. 4. 5.
[Python] 5678. 팰린드롬 https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWXRrK7KhO4DFAUo SW Expert Academy SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요! swexpertacademy.com 재귀함수 호출을 이용하면 쉽게 구현 가능하다. 문자열 길이가 1보다 작거나 같을 때 최대 길이를 비교해서 업데이트 후 탈출하는 것이 포인트 def pal_check(s, depth): global max_len if len(s) 2021. 4. 4.
[Python] 7.3. Nesting app.codility.com/demo/results/training6WQ7HN-NGN/ Test results - Codility A string S consisting of N characters is called properly nested if: S is empty; S has the form "(U)" where U is a properly nested string; S has the form "VW" where V and W are properly nested strings. For example, string "(()(())())" is properly nested but app.codility.com Task Score 100% Correctness 100% Performance 100% .. 2021. 3. 30.
[Python] 7.2. Fish app.codility.com/demo/results/trainingWVD5AJ-4CG/ Test results - Codility You are given two non-empty arrays A and B consisting of N integers. Arrays A and B represent N voracious fish in a river, ordered downstream along the flow of the river. The fish are numbered from 0 to N − 1. If P and Q are two fish and P < Q, then fish app.codility.com Task Score 100% Correctness 100% Performance 100% De.. 2021. 3. 29.
[Python] 7.1. Brackets https://app.codility.com/demo/results/trainingU6MG2S-N29/ Test results - Codility A string S consisting of N characters is considered to be properly nested if any of the following conditions is true: S is empty; S has the form "(U)" or "[U]" or "{U}" where U is a properly nested string; S has the form "VW" where V and W are properly nes app.codility.com Task Score 100% Correctness 100% Performan.. 2021. 3. 27.
728x90
반응형