1051, 1052

qkrrnjswo·2023년 3월 25일
0

백준, 프로그래머스

목록 보기
15/53

1051. 숫자 정사각형

	브루트포스 알고리즘
max_triangle = 1

for i in range(N):
    for j in range(M):
        if N > M:
            for k in range(1,M):
                if i+k < N and j+k < M:
                    if arr[i][j] == arr[i+k][j] and arr[i][j] == arr[i][j+k] and arr[i][j] == arr[i+k][j+k]:
                        max_triangle = max(max_triangle,(k+1)*(k+1))
        else:
            for k in range(1,N):
                if i+k < N and j+k < M:
                    if arr[i][j] == arr[i+k][j] and arr[i][j] == arr[i][j+k] and arr[i][j] == arr[i+k][j+k]:
                        max_triangle = max(max_triangle,(k+1)*(k+1))

print(max_triangle)

1052. 물병

	N을 이진수로 바꿔 생각하면 쉽다.
    예) 13일 때 8, 4, 0, 1 (1101)
    여기에 물명이 하나 씩 계속 산다고 했을 때
    이진수의 1의 개수가 K보다 클때 멈추면 된다.
        N, K = map(int, input().split())

        count = 0

        while bin(N).count('1') > K:
            N = N+1
            count += 1

        print(count)

0개의 댓글